CIS1068-: Syntax Reminders

Miscellaneous
void System.arraycopy(Object src, int srcPos, Object dest, int desPos, int length);
static boolean Arrays.equals(int[] a1, int[] a2);
static String Arrays.toString(int[] a);
ArrayList<T>
boolean add(E o); // append element to end of ArrayList
void add(int index, E o); // insert element at specified position
E get(int ix); // returns element at position ix
E set(int ix, E o); // replace element at position ix with o
int size() // returns the size of the ArrayList
E remove(int ix); // remove element at position ix
Object[] toArray(); // return array with all elements in ArrayList in // same order
T[] toArray(T[] a); // The types of the objects in a determine // the type of Objects returned in the array.
int indexOf(Object elem); // position of first occurrence of elem in // Arraylist (using equals), -1 if not there
Object clone() // Shallow copy of the ArrayList
Wrapper class methods
int intValue(); // applied to an Integer, returns its integer value
int intValue(); // applied to a Double, returns its integer value
double doubleValue(); // applied to a Double, returns its double value
int Integer.parseInt(String s);//returns integer value represented by s
double Double.parseDouble(String s);//returns double value represented by s
Objects of type Integer, Double, .. are immutable. No clone method for them.
throw and throws
try .. catch statement
try { .. }
catch (ExceptionType1 ex){ .. }
catch (ExceptionType2 ex){ .. }
finally { .. }
Exception classes
RuntimeException,ArithmeticException, NumberFormatException, ArrayIndexOutOfBoundsException, ClassCastException, NullPointerException, (all unchecked)
IOException, EOFException,FileNotFoundException (checked exceptions).
Object class
Object clone(); // creates and returns a copy of this object
boolean equals(Object obj); // indicates if some other object is "equal to" this one
String toString(); // returns a string representation of the object
Class getClass(); // returns an object representing the class of the object
String class
int indexOf(String s); // returns position of s, -1 if not there
int indexOf(String s, int k); //returns position of s at or past position k
char charAt(int k); // returns character at position k
String substring(int k); //substring starting at k up to end
String substring(int k, int h); //substring starting at k ending at h excluded
int compareTo(String anotherString);
String toUpperCase();
boolean equalsIgnoreCase(String s);
Strings are immutable. No clone method for them.
Files
Scanner sc = new Scanner(System.in);
Scanner sc = new Scanner(new File(filename));
Scanner sc = new Scanner(aString);
boolean aScanner.hasNext();
String aScanner.next();
boolean aScanner.hasNextLine();
String aScanner.nextLine();
int aScanner.nextInt();
double aScanner.nextDouble();
PrintWriter b = new PrintWriter(new File(filenameString));
void close(); // works for Scanner, PrintWriters