Repository navigation
Expand file tree
/
Copy pathjava-collections.txt
More file actions
39 lines (26 loc) · 1.81 KB
/
Copy pathjava-collections.txt
File metadata and controls
39 lines (26 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Java Collections
### What is a Data Structure?
- A way of storing and organizing data for effective access and modification.
### What are Collections?
- A Collection is a data structure that can be used to store and group objects.
- Java Collections are not part of the native language, but are included in the Java standard library.
- Collection is actually an interface that is extended by a few sub-interfaces like List, Set and Queue.
- Today we will be covering a specific subtype of List: ArrayList
[Java Docs - Collection interface](https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html)
### What are Maps?
- Maps are another data structure provided in the Java standard library.
- It is not a subtype of Collection, therefore it behaves differently.
- Maps are intended to store key-value pairs, similar to Objects in JavaScript.
- Today we will be covering a specific subtype of Map: HashMap
** Both of these libraries can be imported into a Class for use **
### ArrayList
- The ArrayList type acts like a wrapper around a native Java array.
- The methods available on an ArrayList allow us to easily manipulate the ArrayList when adding or accessing elements.
- Unlike Arrays in JavaScript however, collections.ArrayLists can only hold Objects and they must be of the same type.
- Luckily, Java already provides us with "wrapper" classes around primitive types which will allow us to store data like Integers and Doubles in our Collections.
### HashMap
- Similar to Objects in JavaScript, collections.HashMaps store data in key-value pairs
- Keys should all be the same type
- Values should all be the same type
- Keys and Values do NOT have to be the same type. (ie. Keys are Strings and Values are Integers)
[Assigning to ArrayList vs List](https://stackoverflow.com/questions/14974749/assigning-arraylist-to-list)