-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayListNotes.txt
More file actions
36 lines (29 loc) · 1.18 KB
/
arrayListNotes.txt
File metadata and controls
36 lines (29 loc) · 1.18 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
Searchable, maintains insertion order, mutable
declare new array list
List<Integer> scores = new ArrayList<>();
access the scores list; remove last item: scores.remove(length-1);
access the scores list; access last item and add 2x: scores.add(Integer.valueOf(scores.get(length-1) * 2));
ArrayList
Import java.util.ArrayList
List<Integer> result = new ArrayList<>();
result.add(0); <= Initialize 0’s or add numbers if need change
Length: a.size()
Access: a.get(i)
Change item: a.set(0, 5) (index, changeto)
Remove: a.remove(0);
Clear: a.clear();
#items: a.size();
Sort: Collections.sort(a)
ArrayList<Integer> a
Sort: Collections.sort(a)
Create a hashmap: Map<Integer, Integer> differences = new HashMap<>();
Add differences into it: for (int i = 0; i < arr.length-1; i++){
differences.put(arr[i], arr[i+1]-arr[i]); }
Int minDiff = Integer.Max_Value; // set a value to a giant number to calc minimum
Add to frequencyMap: frequencyMap.put(num, frequencyMap.getOrDefault(num,0) +1);
Find the value in freqMap of 1: map over freqMap:if (frequencyMap.get(num) == 1)
for (int num : freqMap.keySet()) { // map over freqMap
if (freqMap.get(num) > 1) { // if freq > 1
dups.add(num); // add to ArrayLlist
}
}