We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a table with names in one column and I have to find out how many different names there are. Of course, double names only count once. I am totally not getting how to do this, though it shouldn'd be so hard :-S . Can anyone please help me?
Answers
Look at reference hashMap()
You can store a string in a hashMap and check if it's already in the hashMap
If I remember correctly you can say
HashMap<String, int> map = new HashMap ();
First try to read the int by giving in the string
If you receive null, string is new, add the string with int value 1
If you receive a value the string is already there. Read the int, add 1 and store back into the map
etc
Look at reference
You could sort the list and then iterate through the entries and count all of them that are different.
Kf
Thank you, this is the easiest way I think!
Store the previous entry and compare to it
Don't use == or != with strings
Use string.equals(a1)
if you don't need to remember the value part of the name / value pair then it's better to use a hashset, which just stores the key part.