Check an array is subset
of another array
Scenario#
Check that
all element of first array present in second array.
Solution#
Apply Brute
force algorithm to check the occurrence of each element of first array into second array.
Solution# Java method
First,
convert arrays into list using arrayList().
Use containsAll()
method to check.
Integer[] array1
= {1,2,3};
Integer[] array2 = { 2,3 };
List list1 = Arrays.asList(array1);
List list2 =
Arrays.asList(array2);
if(list1.containsAll(list2)) {
System.out.println("Yo
Yo ! They are there !");
}
Excellent Example
ReplyDeleteAmazing Article, thank you!. I am very glad to read your informative & practical blog. Kindly keep updating your blog. Java Developer is a wonderful career for IT students.To start Dream Career to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India .
ReplyDelete