> For the complete documentation index, see [llms.txt](https://aloy.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aloy.gitbook.io/notes/languages-frameworks/programming-languages/java/extra/collection-framework.md).

# collection-framework

![Java Collection Hierarchy](https://3935715743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBH37CsSwZp9OqLuOogCr%2Fuploads%2Fgit-blob-eeef85538526a86c59a1b1743eebe694b7f4df19%2Fjava-collection-hierarchy.png?alt=media)

Java Collection Framework provides a set of data structures and interfaces that developers can use to manage and manipulate collections of objects.

* ArrayList
* LinkedList
* Vector
* Stack
* HashSet
* LinkedHashSet
* TreeSet
* HashMap
* LinkedHashMap
* TreeMap
* Hashtable
* Queue (interface)
* PriorityQueue
* ArrayDeque

## Common methods for classes in Collection framework

Common methods in Collection Interface include :

* add
* remove
* contains
* isEmpty
* size
* iterator

### Iterator class

```java
List<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.add("Charlie");

// Has a pointer to an element of the collection it is iterating over
Iterator<String> iterator = names.iterator();

while (iterator.hasNext()) {
    String name = iterator.next();
    System.out.println(name);

    // You can remove elements if needed with iterator.remove();
}
```
