gregrossdev

Greg Ross

Posted on November 10, 2021

Collections

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]            
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode
Documentation

List Interface
ArrayList Class

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);
Enter fullscreen mode Exit fullscreen mode
Documentation

Map Interface

Others

Beyond the scope of my journal

Stack<T>, Queue<T>, Set<T>

💖 💪 🙅 🚩
gregrossdev
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.

Related

Access modifiers
beginners Access modifiers

May 2, 2022

Naming matters
beginners Naming matters

March 11, 2022

OOP Principles
beginners OOP Principles

November 17, 2021

Collections
beginners Collections

November 10, 2021