这个课程的参考视频和图片来自。
主要学到的知识点有:
1. Collection: container that contians objects.
2. Difference between Collection and Array
collection | array | example |
Dynamic siized | fixed sized | int[] grades = new int[20] |
cannot | Primitive types | ArrayList<integer> grades = new ArrayList<>(); |
note: int => Integer
double => Double
3. ArrayList: an implemnetation of a collection.
- Create a ArrayList. (assume that we have a Card class has number and suit)
ArrayListcards = new ArrayList<>():
- Add element in the ArrayList
cards.add(new Card(8, Diamond));
cards.add(new Card(6, Diamond));
- Remove element in the ArrayList
Card temp = cards.remove(0); // will move the first elemnt in the ArrayList
- Set element in the ArrayList
cards.set(0, new Card(3, Diamond)); // will set the first elemnt in the ArrayList
- Get element in the ArrayList
cards.get(0); // will get the first elemnt in the ArrayList
- Insert element in the ArrayList
cards.add(0, new Card(1, Diamond)); // will add Diamond 1 at the first elemnt in the ArrayList