Java Code Manipulation Terms

The flashcards below were created by user DLeck17 on FreezingBlue Flashcards.

  1. How do you instantiate an array?
    • type   Brackets  arrayName = elments
    • String  []  myList = {name1, name2, name3, ......}
    • char [] myChar = myList.toArray();
  2. What does the method .toCharArray() do?
    It splits up a String [i] into individual characters to break up in information stored in myList[j]
  3. What is a HashMap?
    It is a collection of elements stored by a set of keys to values.
  4. How do you access an element stored in a HashMap?
  5. How do you add an element to a Map?
    myMap.put("key", new TYPE (values));
  6. How do you display all the keys in a map?
    • Iterator i = set.iterator();
    • while(i.hasNext()) {
    • Map.Entry me = (Map.Entry);
    • System.out.print(me.getKey() + ": ");
    • System.out.println(me.getValue());
    • }
  7. 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();}
  8. What does the .keySet() method do?
    It returns a set of keys from a HashMap, which is un-ordered.
  9. What does the .toArray() method do?
    it takes any ArrayList or HashMap and turns it into an array of fixed length.
  10. How do I sort through an array?
    use Collections.sort
  11. 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()]);
Card Set
Java Code Manipulation Terms
These are terms that are used manipulating strings and object in Arrays and Maps
Show Answers