D
DrChaos
This should be very trivial and is in C++ Ahhh pointers.
but here i am in java.
All i want to do is:
Dynamically add to an array/list, objects (implemented with
Comparable()) and when i add an object that "compares" is equal to
another object in the array it allows access to that object (through
returning the index or reference) so i can modify it, in a way that does
not effect the "Comparable" function result.
so:
I am adding strings dynamically to a list but if the string is already
in there i want to say that the string now has an increased occurrence count
Comparable myObject:
String s
int count
public int compareTo(Object obj){
return s.compareTo(((myObject)obj).s);
}
If the string 's' matches one in the array, increase its count.
Thats it. simple right?
since this list will be added to dynamically, and could get to about
5000 items long I don't want to do something slow like Use a treeSet and
convert to array at every addition to the set and seek the array :S
I have started to look into TreeMap but i have not seen a good
solution yet.
Ideas?
-Jim aka DrChaos.
but here i am in java.
All i want to do is:
Dynamically add to an array/list, objects (implemented with
Comparable()) and when i add an object that "compares" is equal to
another object in the array it allows access to that object (through
returning the index or reference) so i can modify it, in a way that does
not effect the "Comparable" function result.
so:
I am adding strings dynamically to a list but if the string is already
in there i want to say that the string now has an increased occurrence count
Comparable myObject:
String s
int count
public int compareTo(Object obj){
return s.compareTo(((myObject)obj).s);
}
If the string 's' matches one in the array, increase its count.
Thats it. simple right?
since this list will be added to dynamically, and could get to about
5000 items long I don't want to do something slow like Use a treeSet and
convert to array at every addition to the set and seek the array :S
I have started to look into TreeMap but i have not seen a good
solution yet.
Ideas?
-Jim aka DrChaos.