Last active
August 29, 2015 14:05
-
-
Save vienhoang/cb1a2b4d99a1e0d3d7fe to your computer and use it in GitHub Desktop.
Java: ArrayList
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
import java.util.ArrayList; | |
public class Main { | |
public static void main(String[] args) { | |
/** | |
* ArrayList in Java is for create dynamic arrays | |
*/ | |
ArrayList<String> list = new ArrayList<String>(); | |
// Add string items | |
list.add("Callifornia"); | |
list.add("Oregon"); | |
list.add("Washington"); | |
System.out.println(list); | |
list.add("Alaska"); | |
System.out.println(list); | |
// Remove array item | |
list.remove(0); | |
System.out.println(list); | |
// Get item | |
String state = list.get(1); | |
System.out.println("The second state is: " + state); | |
int pos = list.indexOf("Alaska"); | |
System.out.println("Alaska is at position: " + pos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment