Skip to content

Commit e0b2af6

Browse files
author
turingfly
committed
Generics and Collections
1 parent be56a43 commit e0b2af6

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Java-8/src/genericsAndCollections/ArrayAndArrayList.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public void test() {
2020
// Changes are reflected in both, since they are backed by the same data.
2121
array[0] = "c";
2222
// convert a List to an Array
23-
2423
String[] array2 = (String[]) list.toArray(); // [c, b]
2524

2625
// list.remove(1); throws UnsupportedOperationException

Java-8/src/genericsAndCollections/GenericBound.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static void printList1(List<?> list) {
6363
* used the keyword extends rather than implements .
6464
*/
6565
public static long total(List<? extends Number> list) {
66-
6766
// ArrayList<Number> list = new ArrayList<Integer>(); // DOES NOT
6867
// COMPILE
6968
long count = 0;

Java-8/src/genericsAndCollections/GenericClass.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
/**
44
*
5-
* @author chengfeili Jun 7, 2017 5:44:24 PM
5+
* @author chengfeili
6+
* Jun 7, 2017 5:44:24 PM
67
*
78
* When you instantiate the class, you tell the compiler what T
89
* should be for that particular instance.

Java-8/src/genericsAndCollections/SearchingAndSorting.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ public void test() {
2121
int[] nums = {6, 9, 1, 8};
2222
Arrays.sort(nums); // [1, 6, 8, 9]
2323
System.out.println(Arrays.binarySearch(nums, 6)); // 1
24-
System.out.println(Arrays.binarySearch(nums, 3)); // -2 ( -1 -1 )
24+
System.out.println(Arrays.binarySearch(nums, 3)); // -2 ( -1 -1 = -2)
2525
}
2626
public void test2() {
2727
List<A> list = new ArrayList<>();
2828
list.add(new A());
2929
// Collections.sort(list); Does not compile
3030
Comparator<A> c = (a, b) -> a.id - b.id;
3131
Collections.sort(list, c);
32-
3332
}
3433
}

Java-8/src/genericsAndCollections/UsingQueue.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
/**
77
*
8-
* @author chengfeili Jun 7, 2017 7:52:08 PM
8+
* @author chengfeili
9+
* Jun 7, 2017 7:52:08 PM
10+
*
911
* LinkedList: In addition to being a
10-
* list, it is a double- ended queue. A double-ended queue is different
12+
* list, it is a double-ended queue. A double-ended queue is different
1113
* from a regular queue in that you can insert and remove elements from
1214
* both the front and back of the queue. The main benefit of a
1315
* LinkedList is that it implements both the List and Queue interfaces.

0 commit comments

Comments
 (0)