Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        List<Integer> arraySource = new ArrayList<>();
        for (int i = 0; i < 99999; i++) {
            arraySource.add(i);
        }

        Integer[] myArray = new Integer[999];
        myArray = arraySource.toArray(myArray);
        long startTime = System.currentTimeMillis();
        Arrays.sort(myArray);
        long endTime = System.currentTimeMillis();
        System.out.println("Time take in serial: " + (endTime - startTime) / 1000.0);

        Integer[] myArray2 = new Integer[999];
        myArray2 = arraySource.toArray(myArray);
        startTime = System.currentTimeMillis();
        Arrays.parallelSort(myArray2);
        endTime = System.currentTimeMillis();
        System.out.println("Time take in parallel: " + (endTime - startTime) / 1000.0);

    }
}