Junior — Middle
What are the main classes used for handling data collections in array structures?
sobes.tech AI
Answer from AI
In Android, the following main classes are often used for working with data collections:
- ArrayList — a dynamic array that allows adding and removing elements.
- LinkedList — a linked list, convenient for frequent insertions and deletions.
- HashMap — a collection of key-value pairs with quick access by key.
- HashSet — a set of unique elements.
- SparseArray — an optimized version of HashMap for int type keys, often used to save memory.
Example of using ArrayList:
ArrayList<String> list = new ArrayList<>();
list.add("Android");
list.add("Kotlin");
for (String item : list) {
System.out.println(item);
}