Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package by.vshkl;
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.Set;
- import java.util.TreeSet;
- public class Main {
- public static void main(String[] args) {
- int[] arr1 = {1,2,3,4};
- int[] arr2 = {2,3,4,5};
- int[] arr3 = {3,4,5,6};
- int[] arr4 = {4,5,6,7};
- int[] arr5 = {1,2,3,4};
- int[] arr6 = {3,4,5,6};
- Set<int[]> set = new TreeSet<>(new Comparator<int[]>() {
- @Override
- public int compare(int[] o1, int[] o2) {
- return Arrays.equals(o1, o2) ? 0 : Arrays.hashCode(o1) - Arrays.hashCode(o2);
- }
- });
- set.add(arr1);
- set.add(arr2);
- set.add(arr3);
- set.add(arr4);
- set.add(arr5);
- set.add(arr6);
- for (int[] i : set) {
- for (int j : i) {
- System.out.print(j + " ");
- }
- System.out.println();
- }
- }
- }
- // OUTPUT
- // 1 2 3 4
- // 2 3 4 5
- // 3 4 5 6
- // 4 5 6 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement