How to find the last index of a value in ArrayList with Java

1 Answer

0 votes
import java.util.*; 
  
public class MyClass {
    public static void main(String args[]) {
        ArrayList<Integer> al = new ArrayList<Integer>(Arrays.asList(5, 2, 9, 7, 5, 1)); 
 
        int index = al.lastIndexOf(5);
        System.out.println(index);
        
        index = al.lastIndexOf(36);
        System.out.println(index);
    }
}
  
  
  
  
/*
run:
  
4
-1
  
*/

 



answered Sep 5, 2020 by avibootz
edited Sep 5, 2020 by avibootz

Related questions

1 answer 169 views
1 answer 198 views
1 answer 128 views
2 answers 228 views
1 answer 182 views
1 answer 187 views
...