javaarraysarraylistindexof

Java ArrayList<ArrayList<>> indexOf regardless of the order


I have created an ArrayList containing ArrayLists in Java.

ArrayList<ArrayList<Integer>> arrays = new ArrayList<ArrayList<Integer>>();

Now I'm trying to get the index of a list containing a specific combination of items, regardless of order, using the arrays.indexOf() method.

How can I do this the easiest and fastest way? The array could possibly be very long, so I can't try every possible order.


Solution

  • in other words I only want it to contain the same items

    This means that a Set is more appropriate than a List, since when you compare two Sets, you are checking if they contain the same items. There is no meaning to order.

    ArrayList<Set<Integer>> arrays = new ArrayList<Set<Integer>>();