Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

public class Main {
    public static long iterRemove(List list) {
        ListIterator iter = list.listIterator();
        long start, stop, result = 0;
        for (int i = 0; i < 100; i++) {
            iter.next();
            start = System.nanoTime();
            iter.remove();
            stop = System.nanoTime();
            result += stop - start;
        }
        return result / 100;
    }

    public static long remove(List list) {
        long start, stop, result = 0;
        for (int i = 0; i < 100; i++) {
            start = System.nanoTime();
            list.remove(list.size() - 1 - i);
            stop = System.nanoTime();
            result += stop - start;
        }
        return result / 100;
    }

    public static long remove(Set set) {
        long start, stop, result = 0;
        for (int i = 0; i < 100; i++) {
            start = System.nanoTime();
            set.remove(set.size() - 1 - i);
            stop = System.nanoTime();
            result += stop - start;
        }
        return result / 100;
    }
}