Add to hashmap takes a long time

I am stuck on a few lines in my java program, which takes too much time (about 20 seconds), and it seems strange to me.

Here are the lines

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 have any ideas on where my problem might have arisen?

Thanks!

+6
source share
1 answer

The hashCode() method of java.net.URL performs DNS resolution. The URL class is not suitable for use in a HashSet or as keys in a HashMap . Use either Strings or java.net.URI .

Here is some background:

+14
source

All Articles