 <p>If your lines are strings you can do something like this</p> <pre><code>List&lt;String&gt; a = new ArrayList&lt;&gt;(Arrays.asList(new String[] { "1 2 3", "3 4 5 6", "1 2 4 5 7", "8", "7", "1 2 4" })); List&lt;String&gt; b = new ArrayList&lt;&gt;(Arrays.asList(new String[] { "7", "3 4 5 6", "1 2 4 5 7", "1 2 3", "8", "1 2 4" })); if (a.size() == b.size()) { a.removeAll(b); if (a.isEmpty()) System.out.println("A and B are the same sets"); } </code></pre>