




































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





































Chris Piech CS106A, Stanford University
Changing Variable Types int to String? int x = 5; String xStr = “” + x String to int? String xStr = “5”; int x = Integer.parseInt(x); int to double? int x = 5; double xDbl = x; String to double? String xStr = “5.6”; double x = Double.parseDouble(xStr); Casting double to int double x = 5.2; int y = (int)x; GObject obj = getElementAt(5, 2); GRect objRect = (GRect)obj; GObject to GRect int diff = ‘C'-’A’; char next = (char)‘a’ + diff; int to char
Thanks Keith Schwarz for some great slides to build off! Winter is Coming!
Karel Wars Thanks to Nick Troccoli for the awesome example
list.size() Returns the number of values in the list. list.isEmpty() Returns true if the list is empty. list.set(i, value) Sets the i th entry in the list to value. list.get(i) Returns the i th entry in the list. list.add(value) Adds a new value to the end of the list. list.add(index, value) Inserts the value before the specified index position. list.remove(index) Removes the value at the specified index position. list.clear() Removes all values from the list. Common ArrayList methods
An array is homogeneous. Every value in the array must have the same type.
Arrays in Java
Creating an Array type [] name = new type [ length ];
index 0 1 2 3 4 value 0 0 0 0 0
Crea5ng Arrays
Putting Data In An Array name [ index ] = value ; // set element at index Setting values
Putting Data In An Array name [ index ] = value ; // set element at index
Arrays Of Other Types
Array Length Similar to a String, you can get the length of an array by saying
Ge=ng “length”