I need to print into console part of elements. There is a massive [1,2,4,4,2,3,4,1,7]. I have to find last element, which contains "4", and print the rest of massive after this element. At this manner I have to get [1,7]. Maybe there is exist more simple way, please give me advice.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList <Integer> array = new ArrayList<Integer>();
array.add(0,1);
array.add(1,2);
array.add(2,4);
array.add(3,4);
array.add(4,2);
array.add(5,3);
array.add(6,4);
array.add(7,1);
array.add(8,7);
int i = (Integer) array.lastIndexOf(4); //Java don't uderstand this
for (i = array.lastIndexOf(4); i < array.size()+1; i++) {
System.out.println(array.indexOf(i)); //try to print element 6,7 and 8 of Array
}
}
}