How to find the first index of a value in an Integer array with Java

1 Answer

0 votes
import java.util.Arrays;

public class Program {
    public static void main(String[] args) {
        Integer[] arr = {2, 4, 8, 8, 2, 1, 1, 7, 5, 3, 8, 9, 5, 8};
        
        System.out.println("index = " + Arrays.asList(arr).indexOf(8));
    }
}


 
/*
run
 
index = 2
 
*/


 



answered May 31, 2024 by avibootz

Related questions

1 answer 226 views
1 answer 284 views
2 answers 296 views
4 answers 381 views
2 answers 267 views
1 answer 200 views
1 answer 331 views
...