If I have a list like
[0,0,5,7,9]
I want to get the index position of the number "5", which is 2, and have it stop printing after that.
I've tried doing this, but it will print out 2,3, and 4. Is there a way to have it stop printing after it finds the number "5"?
LinkedList<Integer> list = new LinkedList<Integer>();
list.add(0);
list.add(0);
list.add(5);
list.add(7);
list.add(9);
for(int i = 0; i< list.size(); i++){
if(list.get(i) != 0){
System.out.println(i);
}
}