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 161 views
1 answer 193 views
1 answer 115 views
2 answers 218 views
1 answer 176 views
1 answer 179 views
...