Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

array contains java

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");
        }
    }
}
Comment

java array contains


Arrays.asList(yourArray).contains(yourValue)

Comment

array contain java

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"));
Comment

java can i use contain for array

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
}
Comment

PREVIOUS NEXT
Code Example
Java :: java put a char array into a string 
Java :: base64 in java 
Java :: mobile number validation to edittext in android 
Java :: android list[i] 
Java :: How to find the second smallest value in an array without sorting it in Java? 
Java :: instantiate optinal java 8 
Java :: java % 
Java :: java does file exist 
Java :: how to get data from combobox in java 
Java :: getcurrencyinstance java example 
Java :: Java Queue Array Implementation 
Java :: java localdate to calendar 
Java :: max heap java 
Java :: Java Create LinkedList in Java 
Java :: reverse a integer in java 
Java :: How to determine if a graph contains a cycle, in Java? 
Java :: how to remove duplicate elements from char array in java 
Java :: spring boot actuator 
Java :: hello world java code 
Java :: for loop javasctip 
Java :: terminate a frame java 
Java :: fill two dimensional array columns by columns java 
Java :: java create unmodifiable list 
Java :: java long to integer 
Java :: how to get color from resource android 
Java :: java println 
Java :: classcastexception in java 
Java :: how generate a random number in java between 3 and 5 
Java :: java for loop increment by 3 
Java :: how to reverse a string in java without function 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =