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 :: use regex in if statement java 
Java :: while loop in java 
Java :: volley android 
Java :: dictionary in java 
Java :: Java printf() Method using PrintWriter 
Java :: convert integer array to string array 
Java :: char to ascii java 
Java :: java read integer from text file into array scanner 
Java :: file java class 
Java :: read wss endpoint java 
Java :: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.5.0:repackage failed: 
Java :: bytearrayoutputstream 
Java :: Android: remove shadow from bottom navigation 
Java :: combine two array in java 
Java :: rider find and replace 
Java :: recursion examples java 
Java :: fastreader in java 
Java :: java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead 
Java :: compareto in java string 
Java :: reverse java 
Java :: sound file java 
Java :: java difference hashmap hashtable 
Java :: float.compare java 
Java :: java use variables inside strings 
Java :: on item click listener for recyclerview adapter 
Java :: java access a file 
Java :: how to disable screenshot in react native 
Java :: Simple While Loop Java Example 
Java :: java.lang.IllegalStateException: Could not obtain identifier 
Java :: change text size java 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =