I
I
irklogin2016-03-14 22:37:36
Java
irklogin, 2016-03-14 22:37:36

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

1 answer(s)
E
Evhen, 2016-03-14
@EugeneP2

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 question

Ask a Question

731 491 924 answers to any question