Answer the question
In order to leave comments, you need to log in
How to efficiently remove duplicates from String[]?
I want to say right away that collections cannot be used (ArrayList , HashMap , HashSet etc.)
You need to compare by hashing.
There are hundreds of millions of rows in the array)
Tell me about efficiency, please
Answer the question
In order to leave comments, you need to log in
Why can't collections be used? o_O
1. For this solution, the java.util.HashSet collection is needed. The equals and hashCode methods in the String class are implemented efficiently, so that HashSet will cut off all duplicates without any problems.
2. Why did you load the lines into an array at all? Immediately it was necessary to use HashSet.
3. What makes you think that this is less efficient than pouring everything into an array?
4. The speed of access to the elements of the set is the same as that of the array: O(1).
5. If you load millions of rows into an array, then obviously saving memory is not your priority.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question