Collections
Greg Ross
Posted on November 10, 2021
General idea without bloat of additional coding methods
Structures of Data
Ways to store information in an ordered manner so the data can be called upon when needed. The values can be referenced by index or iterated over where additional processing could be performed.
Common Sequences
Arrays
int[] wholeNumbers = new int[5]; // [item, item, item, item, item]
String[] words = new String[5]; // [item, item, item, item, item]
Lists
import java.util.List;
import java.util.ArrayList;
List<String> listOfideas = new ArrayList<>();
listOfideas.add("serendipity");
listOfideas.add("synchronicity");
listOfideas.add("determinism");
System.out.println(listOfideas);
List<Integer> listOfWholeNumbers = new ArrayList<>();
listOfWholeNumbers.add(5);
listOfWholeNumbers.add(15);
listOfWholeNumbers.add(51);
System.out.println(listOfWholeNumbers);
Documentation
Associative Arrays
Using key:value pairs. Values can be accessed by calling the key of the associated value. Versus where you could need to loop over the entire collection to find the desired value.
import java.util.Map;
import java.util.HashMap;
Map<String, Boolean> animals = new HashMap<String, Boolean>();
animals.put("dog", true);
animals.put("libera", false);
animals.put("girazelle", false);
animals.put("cat", true);
System.out.println(animals);
Documentation
Others
Beyond the scope of my journal
Stack<T>
, Queue<T>
, Set<T>
💖 💪 🙅 🚩
Greg Ross
Posted on November 10, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.