This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Below are the Big O performance of common functions of different Java Collections. | |
| List | Add | Remove | Get | Contains | Next | Data Structure | |
| ---------------------|------|--------|------|----------|------|--------------- | |
| ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array | |
| LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List | |
| CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| An ArrayList, or a dynamically resizing array, is an array that resizes itself as | |
| needed while still providing O(1) access. A typical implementation is that when a | |
| vector is full, the array doubles in size. Each doubling takes O(n) time, but | |
| happens so rarely that its amortized time is still O(1). | |
| public ArrayList<String> merge(String[] words, String[] more) { | |
| ArrayList<String> sentence = new ArrayList<String>(); | |
| for (String w : words) sentence.add(w); | |
| for (String w : more) sentence.add(w); |