This question already has answers here:
What is the difference between a HashMap and a TreeMap? [duplicate]
(8 answers)
Difference between HashMap, LinkedHashMap and TreeMap
(17 answers)
Closed 6 years ago.
In real time project, when we go for HashMap and TreeMap?
In what condition, we choose both?
There are also different data structure in Java Collection, so, what's the reason to use TreeMap or HashMap? and any short example?
Related
This question already has answers here:
Is there a longer than int Java List?
(3 answers)
Using a long as ArrayList index in java
(7 answers)
Closed 7 years ago.
I want to have a big ArrayList, so its index would go beyond int, how or what can I use for that?
I already checked that Vector does have the same issue, any ideas?
This question already has answers here:
Java loop efficiency ("for" vs. "foreach") [duplicate]
(5 answers)
Closed 8 years ago.
What is very faster, normal {for loop} or {foreach loop} in java ?
They are different first of all. for-each uses Iterator under the hood whereas for is useful for operations on arrays or where you can do something meaningful with indexes.
This question already has answers here:
Sorting HashMap by values [duplicate]
(12 answers)
Closed 9 years ago.
I have a java Map
Map<String , String>
The map is like following
olah : 3
vola : 2
sola : 5
jingle : 9
i want to sort the map on the value string like sort on 3,2,5,9 for example...is there any efficient way possible.
I also want to know what difference it will make if i put a map with same values but
like
Map<String , long>
Does it improve any performance...?
See: Sort a Map<Key, Value> by values (Java)
Something like
Map<String , long>
is not possible because Java Collections can not store primitive types. If you want to do that, you can use fastutil http://fastutil.di.unimi.it/ or trove http://trove.starlight-systems.com/. Memory consumption will be better, since no Long objects are created.
This question already has answers here:
Generating Unique Random Numbers in Java
(21 answers)
Closed 9 years ago.
What would be the best way to generate 50,000 unique random values which are put into an ArrayList in Java?
Fill the ArrayList with 50,000 sequential values and call Collections.shuffle(list).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Java Remove Duplicates from an Array?
String={3333,4444,5555,5555,1111}
Using Delimiter i have put the String values in an array[]..
Now, How can i remove the same entries in an Array???
Use Set instead, Or use temporarily Set and get the unique result back to array
See
What interface in Java can I use to store unique objects?