Overview Javas UUID class implements Comparable. But the order it implements appears to be incompatible with the specificiation given in RFC 4122. In particular, it is inconsistent with the natural order implied by its string representation (uuid1.toString().compareTo(uuid2.toString())), which lines up with the RFC. Example You can reproduce and observe the problem by using the following code: Details My main problem
Tag: comparison
Calling equals on string literal
I just was tidying my code a bit and there was this piece: Then I thought of doing it the other way around to get rid of the checking for null: It definitely works, but is this safe to do so? I mean string literals are stored in a common pool, while string object create by new are on the
How do I remove duplicate objects from two separate ArrayLists?
Before beginning, I think that this question has a very simple answer that I’m just overlooking. I figured a few more eyes on the question at hand will be able to point out my problem fairly quickly. I have two ArrayLists that I want to compare and remove duplicates from each of them. The first ArrayList is an ArrayList of
Comparing Numbers in Java
In Java, all numeric types extend from java.lang.Number. Would it be a good idea to have a method like the following: I’m concerned about cases where a double 2.00000 does not equal an int 2. Are these handled by the built-in equals? If not, is there any way to write a simple number compare function in java? (external libraries such
Java Large Files Disk IO Performance
I have two (2GB each) files on my harddisk and want to compare them with each other: Copying the original files with Windows explorer takes approx. 2-4 minutes (that is reading and writing – on the same physical and logical disk). Reading with java.io.FileInputStream twice and comparing the byte arrays on a byte per byte basis takes 20+ minutes. java.io.BufferedInputStream
How to simplify a null-safe compareTo() implementation?
I’m implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other goodies offered by the Java platform): I want the natural ordering for these objects to be: 1) sorted by name and 2) sorted by value if name is the same; both comparisons should be case-insensitive. For both fields null values are