100 likes | 162 Views
Arrays and Array lists. Drew Alvarez and cordie Goodrich. Arrays. Container object Fixed length Composed of elements of a single type Sorted by numerical indices starting with 0 Part of core java programming Primitives or objects. Arrays. Storing and organization of values
E N D
Arrays and Array lists Drew Alvarez and cordie Goodrich
Arrays • Container object • Fixed length • Composed of elements of a single type • Sorted by numerical indices starting with 0 • Part of core java programming • Primitives or objects
Arrays • Storing and organization of values • Declaration: • int[] myArray= new int[3]; • myArray[0] = 5; • myArray[1] = 10; • myArray[2] = 15; • Searching, Copying, Comparing
Arrays 1 4 0 2 3
Array List • Adjustable size • Adjustment takes time • Element of different types • Cannot store primitives • Collections Framework
Array List • Storing and organization of values • + ability to add or remove • Need “import java.util.ArrayList;” • Declaration: • ArrayList<String> list = new ArrayList<String>() • Adjustment: • list.add(“x”); • list.remove(“x”); • Clear, Clone, Capacity adjustments
Sources • http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html • http://java67.blogspot.com/2012/12/difference-between-array-vs-arraylist-java.htm • http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html • http://docs.oracle.com/javase/8/docs/technotes/guides/collections/overview.html • http://stackoverflow.com/questions/1200621/how-to-declare-an-array-in-java • http://www.java-samples.com/showtutorial.php?tutorialid=234 • http://stackoverflow.com/questions/1005073/initialization-of-an-arraylist-in-one-line • http://www.roseindia.net/java/beginners/array_list_demo.shtmlhttp://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/ArrayDemo.java