package com.spring.example.concurrency.collections;

import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

public class SetCollection {

    /**
     * ConcurrentSkipListSet store elements like natural order collection
     *
     * @param args command line arguments
     */
    public static void main(String[] args) {
        Set<Integer> set = new ConcurrentSkipListSet<>();
        //Init set in one thread
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0)
                set.add(i + 500);
            else
                set.add(i);
        }
        System.out.println(set);
        new Thread(() -> {
           for (Integer element : set) {
               System.out.println("Set : " + set);
               System.out.println("Set element: " + element);
               System.out.println("Set size: " + set.size());

           }
        }).start();
        new Thread(() -> {
            for (int i = 0; i < 200; i++) {
                if (i % 2 == 0)
                    set.add(i + 500);
                else
                    set.add(i);
            }
        }).start();
    }
}

@@ -1124,11 +1124,403 @@
 );%0A    %7D
+%0A%0A    //Set in natural order%0A    public static void skipSet() %7B%0A        Set%3CInteger%3E set = new ConcurrentSkipListSet%3C%3E();%0A        new Thread(() -%3E %7B%0A            for (int i = 0; i %3C 200; i++) %7B%0A                if (i %25 2 == 0)%0A                    set.add(i);%0A                else%0A                    set.add(i + 500);%0A            %7D%0A            System.out.println(set);%0A        %7D).start();%0A    %7D
 %0A%7D%0A

Add ConcurrentSkipListSet set with naturel order of elements