JAVA

ArrayList

ArrayList<String/Integer> names = new ArrayList<String/Integer>();
Can input size in () if required

ArrayList<Integer> names = new ArrayList<Integer>(A); (Puts a copy of A into B)

names.add(newString);
Adds an element to the back of the list

names.set(2, newString);
Set an element to a specfic index to an element

names.remove(2);
Remove the 3rd object in ArrayList names

names.contains(newString);
Check if newString appears in names

names.indexOf(newString);
Check the index of an object in names, return -1 if not found

names.get(indexNumber);
Get the object in that certain position

Collections.sort();

Array

.equals();
Check if two objects/ arrays are equal in terms of value
(Note == checks reference whereas .equals() checks value
For objects, the .equals function have to be overwritten!!!)

.compareTo()

Collections.sort();
Sort an ArrayList of comparable objects

Arrays.sort();
Sort a primitive array of comparable objects

.charAt();

.split();

.substring();

.length();

Arrays.sort();

String[] arrays = array.split(“-“); [Split array by the – in it]

Note: It is a method so () is required.

HashMap

HaspMap<Key, Value> hashMapName = new HashMap<Key, Value>();
Or in OOP
private HashMap<String, Item< itemMap;
this.itemMap = new HashMap<String, Item>();
Calls up value via the key, allows you to give a name to an object based on user input.

itemMap.put(itemName, newItem);
Put in the object

myMap.put("foo", new Integer(3));

itemMap.get(itemName);
Calls up the object’s value (via the key)
(Note: If fails, return null)