Generate unique key from List of int in Java

I have many (immutable) lists of Integer values.

A few of them are containing the exact same values. So in order to save memory I'd like to find those. For that reason I'm using a HashMap<String, List<Integer>>

A working approach is to simply concatenate the values to one large String and use it as a key in the HashMap.

This approach works reliably, but it is very slow and consumes a lot of memory.

My Integer values are in between 1 and 100,000,000. The lists are containing in between 1 and 1000 Integer values.

There could be up to 100,000,000 lists.

I need to be sure that there are no collisions.


  • transform the list into a BigInteger
  • Arrays.hashCode() or List.hashCode(), as appropriate.
  • A CRC32
  • An SHA256, 512, ...

You need to find some hash function for your collection. I think this answer may help you -

Try using a Set. Here is an example using Java8. It takes in two lists and creates a separate Set which contains just the duplicate entries from list1 and list2:

    Integer[] a = {1,2,2,3,1};
    List<Integer> list1 = Arrays.asList(a);
    List<Integer> list2 = Arrays.asList(a);

    Set<Integer> duplicates = -> list2.contains(entry)).collect(Collectors.toSet());

Need Your Help

How can I show an error message in an ASP.NET project using a popup window?

c# sql-server

I'm using this code but a compilation error occured. It says that the name server does not exist in current context. If I use Microsoft.SqlServer.Server then .HtmlEncode does not exist in the con...

How to read HTML5 textarea's text with code at the back

javascript html5

I am trying to read the HTML5 Textarea's (not ASP.NET textbox control) text and pass it to my aspx.vb code at the back of the web page. How can I do it?