Appearance
Data Structures
Arrays:
Arrays are fixed-size, ordered collections of elements of the same type.
java
// Arrays
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};
ArrayList:
ArrayList
is a resizable, ordered collection of elements that can dynamically grow or shrink.
java
// ArrayList
import java.util.ArrayList;
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.remove(1); // Remove element at index 1 (value 2)
LinkedList:
LinkedList
is a data structure consisting of a sequence of elements, where each element points to the next element in the sequence.
java
// LinkedList
import java.util.LinkedList;
LinkedList<String> names = new LinkedList<>();
names.add("Alice");
names.add("Bob");
names.add("Charlie");
names.removeFirst(); // Remove the first element ("Alice")
HashMap:
HashMap
is a collection of key-value pairs, where each key is unique.
java
// HashMap
import java.util.HashMap;
HashMap<String, Integer> grades = new HashMap<>();
grades.put("Math", 90);
grades.put("Science", 85);
grades.put("History", 78);