import java.util.Scanner;
import java.util.Arrays;
public class ArrayContains {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of elements ");
int elements = input.nextInt();
System.out.println("Enter the " + elements + " numbers");
int[] numbers = new int[elements];
for (int i = 0; i < numbers.length; i++) {
System.out.println("Please enter number");
numbers[i] = input.nextInt();
}
System.out.println("Check if number is inside of an array");
int n = input.nextInt();
if (Arrays.asList(elements).contains(n)) {
System.out.println("True");
} else {
System.out.println("False");
}
}
}
Arrays.asList(yourArray).contains(yourValue)
Integer[] intArray = new Integer[]{1, 2, 3, 4, 5};
String[] nameArray = new String[]{"John", "Mark", "Joe", "Bill", "Connor"};
List<Integer> intList = new ArrayList<>(Arrays.asList(intArray));
List<String> nameList = new ArrayList<>(Arrays.asList(nameArray));
System.out.println(intList.contains(12));
System.out.println(nameList.contains("John"));
import java.util.Arrays;
// For String
String[] array = {"Boto", "Nesto", "Lepta"};
String toSearch = "Nesto";
// Inline
if (Arrays.toString(array).contains(toSearch)) {
// Do something if it's found
}