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 :: get block player is looking at bukkit 
Java :: java multiplication table nested loop 
Java :: jsp import 
Java :: Authentication Server with spring, JWT & JPA 
Java :: java import set and hashset 
Java :: add extension quarkus 
Java :: close scanner java 
Java :: primefaces datepicker validation 
Java :: how to set 2 decimal places in java 
Java :: formartted string java 
Java :: show input dialog java 
Java :: android studio get string 
Java :: first java program 
Java :: last day of month from localdate java 
Java :: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null 
Java :: java check if divisible 
Java :: abstract vs final 
Java :: How to efficiently find the highest power of 2 dividing a given number, in Java? 
Java :: java ModelMapper class 
Java :: read file in java 
Java :: java equals ignore case 
Java :: swap function java 
Java :: java random char 
Java :: how to set title in center in toolbar in android 
Java :: convert int to double with 2 decimal places java 
Java :: create new java swing button 
Java :: random word java 
Java :: solid principles in programming 
Java :: How to perform a breadth first search through a binary tree, in Java? 
Java :: spring boot procfile run profile 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =