Home
Flashcards
Preview
Java Code Manipulation Terms
Home
Get App
Take Quiz
Create
How do you instantiate an array?
type Brackets arrayName = elments
String [] myList = {name1, name2, name3, ......}
char [] myChar = myList.toArray();
What does the method .toCharArray() do?
It splits up a String [i] into individual characters to break up in information stored in myList[j]
What is a HashMap?
It is a collection of elements stored by a set of keys to values.
How do you access an element stored in a HashMap?
myMap.get("key");
How do you add an element to a Map?
myMap.put("key", new TYPE (values));
How do you display all the keys in a map?
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print(me.getKey() + "
: ");
System.out.println(me.getValue());
}
How do you pick a random key from a Map and display it?
{Object[] pick = cardMap.keySet().toArray();
Object key = pick[new Random().nextInt(pick.length)];
System.out.println("* Random Value * \n" + key); System.out.println();}
What does the .keySet() method do?
It returns a set of keys from a HashMap, which is un-ordered.
What does the .toArray() method do?
it takes any ArrayList or HashMap and turns it into an array of fixed length.
How do I sort through an array?
use Collections.sort
How do I use the .toArray() method?
Take any List or Map and:
List<T> list = new ArrayList<T>();
T [] countries = list.toArray(new T[list.size()]);
Author
DLeck17
ID
260353
Card Set
Java Code Manipulation Terms
Description
These are terms that are used manipulating strings and object in Arrays and Maps
Updated
2014-02-05T15:08:50Z
Home
Flashcards
Preview