UserPreferences

JavaDataStructures


Java Data Structures

1. Data Manipulation

Parsing is the process of breaking a file or string into pieces, or tokens.

1.1. StringTokenizer

int countTokens()
boolean hasMoreTokens()
String nextToken()
String nextToken(String delimiters)
StringTokenizer st = new StringTokenizer(someString); // default delimiter is any whitespace
while (st.hasMoreTokens()) {
   nextString = st.nextToken();
   // process next token
}

2. Collections

A collection is a group of objects. This interface standardizes the way in which you interact with different collection-based groups.

All collections define the following methods (and more):

boolean add(Object o) 
boolean addAll(Collection c) 
void clear() 
boolean contains(Object o)
boolean containsAll(Collect c)
boolean isEmpty()
Iterator iterator()
boolean remove(Object o)
boolean removeAll(Collection c)
boolean retainAll(Collection c)
int size()
Object [] toArray()

New in Java 1.4 are the following classes:

2.1. Lists

A list is a data structure designed to handle data as a sequence.

All lists define the following methods:

2.1.1. LinkedList

2.2. Sets

A set defines a group with unique members.

2.2.1. SortedSet

2.3. Maps

A map is a collection organized as key/value pairs.

2.4. HashMap

3. Algorithms

3.1. Iterator