13. API
http://java.sun.com/javase/6/docs/api/
Tutorial
http://java.sun.com/docs/books/tutorial/java/TOC.html
14. Variables - Naming
• Subsequent characters also can be numbers
• Case sensitive
• No spaces
• Examples:
name
firstName
phoneNumber
15. Reserved Words
abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
39. Example
ArrayList<String> arrList = new ArrayList<String>();
arrList.add(“A”);
arrList.add(“AB”);
arrList.add(“ABC”);
arrList.add(“ABCD”);
// using indices
arrList.set(0, arrList.get(1));
arrList.set(1, “foo”);
// out of bound?
arrList.set(9, “bar”);
40. Example
• Suppose an ArrayList A1
• What does the following line mean?
List<String> list =
new ArrayList<String>(A1);
41. for-each Construct
• Looping by indices
• for-each, parallel execution
for (Object o : collection)
System.out.println(o);
42. Collection Operations
List<Type> list1 = new ArrayList<Type>();
// …
List<Type> list2 = new ArrayList<Type>();
// …
List<Type> list3 = new ArrayList<Type>(list1);
list3.addAll(list2);
43. List Algorithms
• sort — sorts a List using a merge sort algorithm, which provides a
fast, stable sort. (A stable sort is one that does not reorder equal
elements.)
• shuffle — randomly permutes the elements in a List.
• reverse — reverses the order of the elements in a List.
• rotate — rotates all the elements in a List by a specified distance.
• swap — swaps the elements at specified positions in a List.
• replaceAll — replaces all occurrences of one specified value with
another.
• fill — overwrites every element in a List with the specified value.
• copy — copies the source List into the destination List.
• binarySearch — searches for an element in an ordered List using the
binary search algorithm.
• indexOfSubList — returns the index of the first sublist of one List that
is equal to another.
• lastIndexOfSubList — returns the index of the last sublist of
one List that is equal to another.
See more @ http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html