Last active
August 29, 2015 14:18
-
-
Save bikrone/44ed8c9716938f66a1dc to your computer and use it in GitHub Desktop.
Java snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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