Skip to content

Commit 8b9a7a2

Browse files
committed
Tidy up binary search hints and reference implementation
1 parent d6e6697 commit 8b9a7a2

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

exercises/binary-search/.meta/hints.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ You have to specify which type you want to put into the class when you construct
1111

1212
For example you could construct a list of `Integers`:
1313

14-
`List<Integer> someList = new LinkedList();`
14+
`List<Integer> someList = new LinkedList<>();`
1515

1616
Now `someList` can only contain `Integers`. You could also do:
1717

18-
`List<String> someOtherList = new LinkedList()`
18+
`List<String> someOtherList = new LinkedList<>()`
1919

2020
Now `someOtherList` can only contain `Strings`.
2121

2222
Another constraint is that any type used with generics cannot be a [primitive type](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html), such as `int` or `long`.
23+
However, every primitive type has a corresponding reference type, so instead of `int` you can use [`Integer`](https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html) and instead of `long` you can use [`Long`](https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html).
2324

2425
It can help to look at an [example use case of generics](https://docs.oracle.com/javase/tutorial/java/generics/types.html) to get you started.

exercises/binary-search/.meta/src/reference/java/BinarySearch.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11

22
import java.util.List;
33

4-
public class BinarySearch<T extends Comparable<T>> {
4+
class BinarySearch<T extends Comparable<T>> {
55

66
private List<T> array;
77
private int arraySize;
88

9-
public BinarySearch(List<T> array) {
9+
BinarySearch(List<T> array) {
1010
this.array = array;
1111
this.arraySize = array.size();
1212
}
1313

14-
public int indexOf(T value) {
14+
int indexOf(T value) {
1515
return search(value);
1616
}
1717

18-
public List<T> getArray() {
19-
return array;
20-
}
21-
2218
private int search(T value) {
2319
int left = 0;
2420
int right = this.arraySize - 1;

0 commit comments

Comments
 (0)