package ru.sbulygin;

import java.util.Collection;
import java.util.Iterator;

/**
 * Class CollectionsTest.
 *
 * @author ru.sbulygin.
 * @since 09.04.2017.
 * @version 1.0.
 */
public class CollectionsTest {

    public long add(Collection<String> collection, String line, int amount) {

        long startTime = System.currentTimeMillis();

        for (int index = 0; index < amount; index++) {
            collection.add(line);
        }
        long finishTime = System.currentTimeMillis();
        return finishTime - startTime;
    }

    public long delete(Collection<String> collection, int amount) {

        long startTime = System.currentTimeMillis();

        Iterator<String> iterator = collection.iterator();

        for (int index = 0; index < amount; index++) {

            if (iterator.hasNext()) {
                iterator.next();
                iterator.remove();
            }
        }
        long finishTime = System.currentTimeMillis();
        return finishTime - startTime;
    }



}

@@ -36,45 +36,9 @@
 til.
-Collection;%0Aimport java.util.Iterator
+*
 ;%0A%0A/
@@ -969,12 +969,1175 @@
 %0A    %7D%0A%0A
+public static void main(String%5B%5D args) %7B%0A%0A    CollectionsTest test = new CollectionsTest();%0A    LinkedList%3CString%3E linkedList = new LinkedList%3C%3E();%0A    ArrayList%3CString%3E arrayList = new ArrayList%3C%3E();%0A    TreeSet%3CString%3E treeSet = new TreeSet%3C%3E();%0A%0A    System.out.println(%22Time adding elements: %22);%0A    System.out.println(String.format(%22LinkedList: %25s ms%22, test.add(linkedList, %22element%22, 7_000_000)));%0A    System.out.println(String.format(%22arrayList: %25s ms%22, test.add(arrayList, %22element%22, 7_000_000)));%0A    System.out.println(String.format(%22treeSet: %25s ms%22, test.add(treeSet, %22element%22, 7_000_000)));%0A    linkedList.clear();%0A    arrayList.clear();%0A    treeSet.clear();%0A%0A    test.add(linkedList, %22element%22, 180_000);%0A    test.add(arrayList, %22element%22, 180_000);%0A    test.add(treeSet, %22element%22, 180_000);%0A    System.out.println();%0A    System.out.println(%22Time of delete elements: %22);%0A    System.out.println(String.format(%22LinkedList: %25s ms%22, test.delete(linkedList, 120_000)));%0A    System.out.println(String.format(%22arrayList: %25s ms%22, test.delete(arrayList, 120_000)));%0A    System.out.println(String.format(%22treeSet: %25s ms%22, test.delete(treeSet, 120_000)));%0A%0A%0A%0A%7D
 %0A%0A%7D%0A

create method main #1