-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListIndexOf.java
More file actions
36 lines (24 loc) · 877 Bytes
/
ArrayListIndexOf.java
File metadata and controls
36 lines (24 loc) · 877 Bytes
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
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
public class ArrayListIndexOf{
public static void main(String[] args){
ArrayList<Word> a = new ArrayList<>();
a.add(new Word("Most"));
a.add(new Word("Lost"));
a.add(new Word("Lost"));
a.add(new Word("Lost"));
a.add(new Word("Most"));
System.out.println(a.indexOf(new Word("Lost")));
System.out.println(a.lastIndexOf(new Word("Lost")));
Comparator<Word> compare = new Comparator<Word>() {
public int compare(Word o1, Word o2){
return o1.getSorted().compareToIgnoreCase(o2.getSorted());
}
};
int index = Collections.binarySearch(
a, new Word("Lost"),compare);
System.out.println(index);
}
}