data structure an code example
Example 1: data structures
Data Structures
in Java: Array, Collections Framework, Map.
1-ARRAY:
- It is fixed size.
- Ordered
-Allows Duplicates
-Can store Primitives and objects
-Can be multi-dimensional
-Build in data structure
2-COLLECTIONS: (LIST, SET, QUQUE)
List: Can store duplicate values,
Keeps the insertion order.
It allows multiple null values,
Also we can read a certain value by index.
- ArrayList not syncronized, array based class
- LinkedList not synchronized, doubly linked
- Vector is synchronized, thread safe
Set: Can only store unique values,
And does not maintain order
- HashSet can have null, order is not guaranteed
- LinkedHashSet can have null and keeps the order
- TreeSet sorts the order and don't accept null
Quque : Accepts duplicates,
Doesn't have index num,
First in first our order.
3-MAP:
is a (key-value format)
and keys are always unique,
and value can be duplicated.
- HashTable don't have null key, sychronized(thread-safe)
- LinkedHashMap can have null key, keeps order
- HasHMap can have null key, order is not guaranteed
- TreeMap doesn't have null key and keys are sorted
Example 2: data structures used
Depending on the data that I am working with, I use
Arrays, Lists, Sets, Maps.