Skip to content

Instantly share code, notes, and snippets.

@bikrone
Last active August 29, 2015 14:18
Show Gist options
  • Save bikrone/44ed8c9716938f66a1dc to your computer and use it in GitHub Desktop.
Save bikrone/44ed8c9716938f66a1dc to your computer and use it in GitHub Desktop.
Java snippet
// Array list
List listA = new ArrayList();
listA.add("element 0");
listA.add("element 1");
listA.add("element 2");
//access via index
String element0 = listA.get(0);
String element1 = listA.get(1);
String element3 = listA.get(2);
//access via Iterator
Iterator iterator = listA.iterator();
while(iterator.hasNext(){
String element = (String) iterator.next();
}
//access via new for-loop
for(Object object : listA) {
String element = (String) object;
}
// sort a collection
Collections.sort(listA);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment