About 12,900,000 results
Open links in new tab
  1. java - boolean to detect an element in array - Stack Overflow

    Oct 29, 2013 · public boolean check; public static boolean linearSearch(int[] array, int target){ check = false; for(int i = 0; i < array.length; i++){ if(array[i] == target){ check = true; } } return check; }

  2. Check If a Value is Present in an Array in Java - GeeksforGeeks

    Apr 15, 2025 · Our task is to check whether the key element is present in the array. If the element (key) is present in the array, return true; otherwise, return false. Example: Input: arr[] = [3, 5, 7, 2, 6, 10], key = 7 Output: Is 7 present in the array: true Input: arr[] = [-1, 1, 5, 8], key = -2 Output: Is -2 present in the array: false . Approaches

  3. Java Booleans - W3Schools

    Boolean Expression. A Boolean expression returns a boolean value: true or false. This is useful to build logic, and find answers. For example, you can use a comparison operator, such as the greater than (>) operator, to find out if an expression (or a variable) is true or false:

  4. How to Check If All Values in List are True in Java - LogFetch

    We can also check if a list is entirely true or entirely false using the Stream API and Boolean::booleanValue. Suppose we have a boolean list in Java that might look something like this. List<Boolean> list = Arrays.

  5. How to Elegantly Check If All Values in a Boolean Array are True in Java?

    In Java, checking if all values in a boolean array are true can be achieved in several ways. The most elegant solution typically utilizes streams if you are working with Java 8 or later. Here is a breakdown of various methods to perform this check.

  6. java - What is the most elegant way to check if all values in a boolean

    You can check all value items are true or false by compare your array with the other boolean array via Arrays.equal method like below example :

  7. Check if a Java Array Contains a Value - Baeldung

    Sep 7, 2024 · In this article, we’ll look at different ways to search an array for a specified value. We’ll also compare how these perform using JMH (the Java Microbenchmark Harness) to determine which method works best.

  8. How to check if Array contains given Number or String in Java

    How to check if an array contains a given value in Java? Given the String name, you need to return true or false, depending upon whether names contain that value or not. By the way, here is a full example of how to search a number on an integer array and searching for a name on String array, in case you need any help.

  9. Java Guava | Booleans.contains() method with Examples

    Jan 30, 2019 · The contains(Object element) of java.util.Collection interface is used to check whether the element 'element' exists in this collection. This method returns a boolean value depicting the presence of the element. If the element is present, it returns true, else it returns false. Syntax: Collection.co

  10. How to Check if an Array Contains a Value in Java Efficiently?

    Apr 7, 2014 · If the array is sorted, you can use the following code to search the target element: public static boolean useArraysBinarySearch ( String [ ] arr, String targetValue ) { int a = Arrays . binarySearch ( arr, targetValue ) ; if ( a > 0 ) return true ; else return false ; }

  11. Some results have been removed
Refresh