Skip to content

Instantly share code, notes, and snippets.

@jayjaykim
Created August 27, 2016 02:27
Show Gist options
  • Save jayjaykim/84d631a5cadc66cc787004fcf90ed604 to your computer and use it in GitHub Desktop.
Save jayjaykim/84d631a5cadc66cc787004fcf90ed604 to your computer and use it in GitHub Desktop.
remove an entry in for-loop statement
public class TestList {
public static void main(String[] args) {
String[] strings = {"hi", "hello", "mine", "you"};
List<String> list = Lists.newArrayList(strings);
// item or entry == 항목
System.out.println("list : " + list);
final int size = list.size();
for(int i = size - 1; i >= 0; i--) {
if("mine".equals(list.get(i))) {
// TODO: 2016. 8. 27. remove the item
list.remove(i);
}
}
System.out.println("list : " + list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment