Java – adding to HashMap takes a long time
•
Java
In my java program, I have stopped for a few lines, which takes too much time (about 20 seconds), which seems strange to me
This is a thread
Map<URL,Integer> res2 = new HashMap<>(); for (URL url : res) { res2.put(url,null); }
Which res is defined as follows:
List<URL> res = new ArrayList<>();
In my program, res.size() ~ = 1500
Do you know where my problem may come from?
thank you!
Solution
java. net. The hashcode () method of the URL performs DNS resolution The URL class is not suitable for use in HashSet or as a key in HashMap Use string or Java net. URI.
Here are some background knowledge:
> Michael Scharf: java. net. URL. equals and hashCode make (blocking) Internet connections…. > Eishay Smith: Java's URL little secret (link in robau's comments on this answer)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码