Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java indexof array

java.util.Arrays.asList(theArray).indexOf(o)
Comment

indexof an array in java

import java.util.ArrayList;

class Main {
    public static void main(String[] args) {
        // create an ArrayList
        ArrayList<Integer> numbers = new ArrayList<>();

        // insert element to the arraylist
        numbers.add(22);
        numbers.add(13);
        numbers.add(35);
        System.out.println("Number ArrayList: " + numbers);

        // find the position of 13
        int position1 = numbers.indexOf(13);
        System.out.println("Index of 13: " + position1);

        // find the position of 50
        int position2 = numbers.indexOf(50);
        System.out.println("Index of 50: " + position2);
    }
}
Comment

index of function in java for array

// Java program to find index of
// an element in N elements
import java.util.stream.IntStream;
public class index {
  
    // Function to find the index of an element
    public static int findIndex(int arr[], int t)
    {
        int len = arr.length;
        return IntStream.range(0, len)
            .filter(i -> t == arr[i])
            .findFirst() // first occurrence
            .orElse(-1); // No element found
    }
    public static void main(String[] args)
    {
        int[] my_array = { 5, 4, 6, 1, 3, 2, 7, 8, 9 };
        System.out.println("Index position of 5 is: "
                           + findIndex(my_array, 5));
        System.out.println("Index position of 7 is: "
                           + findIndex(my_array, 7));
    }
}
Comment

java array get index

 public int getArrayIndex(int[] arr,int value) {

        int k=0;
        for(int i=0;i<arr.length;i++){

            if(arr[i]==value){
                k=i;
                break;
            }
        }
    return k;
}
Comment

PREVIOUS NEXT
Code Example
Java :: change number into array in java 
Java :: java how to cast int to String 
Java :: create stream from array java 
Java :: bubble sort for java ArrayList 
Java :: AmazonS3ClientBuilder 
Java :: string array to string java 
Java :: how to write deserlizer java 
Java :: java bigdecimal check less zero 
Java :: jframe in java 
Java :: JAVA HashMap get keys by values 
Java :: java logger 
Java :: if number is negative java 
Java :: in java how to throw exception from function 
Java :: random numbers java 
Java :: How to count the number of islands (groups of adjacent 1s) in a grid of 1s (land) and 0s (water), in Java? 
Java :: java mp3 player 
Java :: play mp3 android java 
Java :: input array in String in java 
Java :: java join two list 
Java :: java get bigger int 
Java :: java check if number is in range 
Java :: how to declare and insert value to arraylist in same line in java 
Java :: how to assert that an exception is thrown java 
Java :: byte array to file java 
Java :: Processing Java examples 
Java :: Spring boot enable openapi swagger accessed 
Java :: export java_home linux 
Java :: get minimum of array java 
Java :: datatypes in java 
Java :: how to find some of digits in java 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =