An array of 10 Elements with some number are missing, How will you find the missing numbers?


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

public class MissingElementsNoLoop {

    public static void main(String[] args) {

        Integer[] numberArray1 = new Integer[10];
        for (int i = 0; i < numberArray1.length; i++) {
            numberArray1[i] = i + 1;
        }
        Integer[] numberArray2 = {1, 2, 4, 5, 7, 8, 9};
        List list1 = new ArrayList(Arrays.asList(numberArray1));
        System.out.println("All Elements List::" + list1);
        List list2 = new ArrayList(Arrays.asList(numberArray2));
        System.out.println("Input Elements List::" + list2);
        list1.removeAll(list2);
        System.out.println("Missed Elements List::" + list1);
    }

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s