Answers for "how to check in an array has a specific value in java"

5

java check if element exists in array

package com.mkyong.core;

import java.util.Arrays;
import java.util.List;

public class StringArrayExample1 {

    public static void main(String[] args) {

        String[] alphabet = new String[]{"A", "B", "C"};

        // Convert String Array to List
        List<String> list = Arrays.asList(alphabet);
        
        if(list.contains("A")){
            System.out.println("Hello A");
        }

    }

}
Copy
Posted by: Guest on April-07-2020
0

check if array contains a number in java

public static boolean contains(final int[] arr, final int key) {
    return Arrays.stream(arr).anyMatch(i -> i == key);
}
Posted by: Guest on May-24-2021
5

java check if element exists in array

package com.mkyong.core;

import java.util.Arrays;
import java.util.List;

public class StringArrayExample1 {

    public static void main(String[] args) {

        String[] alphabet = new String[]{"A", "B", "C"};

        // Convert String Array to List
        List<String> list = Arrays.asList(alphabet);
        
        if(list.contains("A")){
            System.out.println("Hello A");
        }

    }

}
Copy
Posted by: Guest on April-07-2020
0

check if array contains a number in java

public static boolean contains(final int[] arr, final int key) {
    return Arrays.stream(arr).anyMatch(i -> i == key);
}
Posted by: Guest on May-24-2021

Code answers related to "how to check in an array has a specific value in java"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language