I'm trying to use HashSet to store objects of a class that I created, but apparently the same objects seem to have two different hashes, which is why the contains method ...
Example:
I have a BitSet of 120 bits (010*0*001000......). Now I want to modify the 4th bit which is set to zero to 1.
SET(4,TRUE) - Something like this. Can it be ...
I have a person class which has a name and a list of friends in HashSet.
I want to override an equals method for this Person class. Below is what I have ...
Order appears to be determined at insertion. I don't know of a way to "re-order" the TreeSet if elements change. import java.util.*; class MyObject { int value; MyObject(int i) { value = i; } public boolean equals(Object ob) { MyObject m = (MyObject)ob; if(m.value == value) return true; else return false; } public String toString() { return "ObValue" + value; } ...
Vinney: Ok, here's the relevant part of the TreeSet javadoc: Note that the ordering maintained by a set (whether or not an explicit comparator is provided) must be consistent with equals if it is to correctly implement the Set interface. (See Comparable or Comparator for a precise definition of consistent with equals.) This is so because the Set interface is defined ...
import java.util.*; public class TestTree { public static void main (String[] args) { new TestTree().go(); } public void go() { Book b1 = new Book("How Cats Work"); System.out.println(b1); Book b2 = new Book("Remix your Body"); Book b3 = new Book("Finding Emo"); TreeSet tree = new TreeSet(); tree.add(b1); System.out.println(b1); // tree.add(b2); // System.out.println(tree); // tree.add(b3); System.out.println(tree); } } class Book { String ...
I'm implementing huffman compression , so does any body know an efficient way for reading and writing bits ?? there are a lot of java classes that support reading and writing bytes , can anything similar but for bits be found ?? wishing to find a solution .. thanks in advance . Regards, D.Roth