8000 update · ninjayoto/Java-Coding-Problems@9c2558d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c2558d

Browse files
committed
update
1 parent 4d5e9b5 commit 9c2558d

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

Chapter_05/P100_FindElementInArray/src/modern/challenge/ArrayFinds.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,152 +10,152 @@ private ArrayFinds() {
1010
throw new AssertionError("Cannot be instantiated");
1111
}
1212

13-
public static boolean containsElementV1(int[] arr, int find) {
13+
public static boolean containsElementV1(int[] arr, int toContain) {
1414

1515
if (arr == null) {
1616
throw new IllegalArgumentException("Array cannot be null");
1717
}
1818

1919
for (int elem : arr) {
20-
if (elem == find) {
20+
if (elem == toContain) {
2121
return true;
2222
}
2323
}
2424

2525
return false;
2626
}
2727

28-
public static boolean containsElementV2(int[] arr, int find) {
28+
public static boolean containsElementV2(int[] arr, int toContain) {
2929

3030
if (arr == null) {
3131
throw new IllegalArgumentException("Array cannot be null");
3232
}
3333

3434
Arrays.sort(arr);
35-
int index = Arrays.binarySearch(arr, find);
35+
int index = Arrays.binarySearch(arr, toContain);
3636

3737
return (index >= 0);
10000
3838
}
3939

40-
public static boolean containsElementV3(int[] arr, int find) {
40+
public static boolean containsElementV3(int[] arr, int toContain) {
4141

4242
if (arr == null) {
4343
throw new IllegalArgumentException("Array cannot be null");
4444
}
4545

4646
return Arrays.stream(arr)
47-
.anyMatch(e -> e == find);
47+
.anyMatch(e -> e == toContain);
4848
}
4949

50-
public static <T> boolean containsElementObjectV1(T[] arr, T find) {
50+
public static <T> boolean containsElementObjectV1(T[] arr, T toContain) {
5151

52-
if (arr == null || find == null) {
52+
if (arr == null || toContain == null) {
5353
throw new IllegalArgumentException("None of the arguments can be null");
5454
}
5555

5656
for (T elem : arr) {
57-
if (elem.equals(find)) {
57+
if (elem.equals(toContain)) {
5858
return true;
5959
}
6060
}
6161

6262
return false;
6363
}
6464

65-
public static <T> boolean containsElementObjectV2(T[] arr, T find, Comparator<? super T> c) {
65+
public static <T> boolean containsElementObjectV2(T[] arr, T toContain, Comparator<? super T> c) {
6666

67-
if (arr == null || find == null || c == null) {
67+
if (arr == null || toContain == null || c == null) {
6868
throw new IllegalArgumentException("None of the arguments can be null");
6969
}
7070

7171
for (T elem : arr) {
72-
if (c.compare(elem, find) == 0) {
72+
if (c.compare(elem, toContain) == 0) {
7373
return true;
7474
}
7575
}
7676

7777
return false;
7878
}
7979

80-
public static <T> boolean containsElementObjectV3(T[] arr, T find, Comparator<? super T> c) {
80+
public static <T> boolean containsElementObjectV3(T[] arr, T toContain, Comparator<? super T> c) {
8181

82-
if (arr == null || find == null || c == null) {
82+
if (arr == null || toContain == null || c == null) {
8383
throw new IllegalArgumentException("None of the arguments can be null");
8484
}
8585

8686
Arrays.sort(arr, c);
87-
int index = Arrays.binarySearch(arr, find, c);
87+
int index = Arrays.binarySearch(arr, toContain, c);
8888

8989
return (index >= 0);
9090
}
9191

92-
public static int findIndexOfElementV1(int[] arr, int find) {
92+
public static int findIndexOfElementV1(int[] arr, int toFind) {
9393

9494
if (arr == null) {
9595
throw new IllegalArgumentException("Array cannot be null");
9696
}
9797

9898
for (int i = 0; i < arr.length; i++) {
99-
if (arr[i] == find) {
99+
if (arr[i] == toFind) {
100100
return i;
101101
}
102102
}
103103

104104
return -1;
105105
}
106106

107-
public static int findIndexOfElementV2(int[] arr, int find) {
107+
public static int findIndexOfElementV2(int[] arr, int toFind) {
108108

109109
if (arr == null) {
110110
throw new IllegalArgumentException("Array cannot be null");
111111
}
112112

113113
return IntStream.range(0, arr.length)
114-
.filter(i -> find == arr[i])
114+
.filter(i -> toFind == arr[i])
115115
.findFirst()
116116
.orElse(-1);
117117
}
118118

119-
public static <T> int findIndexOfElementObjectV1(T[] arr, T find) {
119+
public static <T> int findIndexOfElementObjectV1(T[] arr, T toFind) {
120120

121-
if (arr == null || find == null) {
121+
if (arr == null || toFind == null) {
122122
throw new IllegalArgumentException("None of the arguments can be null");
123123
}
124124

125125
for (int i = 0; i < arr.length; i++) {
126-
if (arr[i].equals(find)) {
126+
if (arr[i].equals(toFind)) {
127127
return i;
128128
}
129129
}
130130

131131
return -1;
132132
}
133133

134-
public static <T> int findIndexOfElementObjectV2(T[] arr, T find, Comparator<? super T> c) {
134+
public static <T> int findIndexOfElementObjectV2(T[] arr, T toFind, Comparator<? super T> c) {
135135

136-
if (arr == null || find == null || c == null) {
136+
if (arr == null || toFind == null || c == null) {
137137
throw new IllegalArgumentException("None of the arguments can be null");
138138
}
139139

140140
for (int i = 0; i < arr.length; i++) {
141-
if (c.compare(arr[i], find) == 0) {
141+
if (c.compare(arr[i], toFind) == 0) {
142142
return i;
143143
}
144144
}
145145

146146
return -1;
147147
}
148148

149-
public static <T> int findIndexOfElementObjectV3(T[] arr, T find, Comparator<? super T> c) {
149+
public static <T> int findIndexOfElementObjectV3(T[] arr, T toFind, Comparator<? super T> c) {
150150

151-
if (arr == null || find == null || c == null) {
151+
if (arr == null || toFind == null || c == null) {
152152
throw new IllegalArgumentException("None of the arguments can be null");
153153
}
154154

155155
return IntStream.range(0, arr.length)
156-
.filter(i -> c.compare(find, arr[i]) == 0)
156+
.filter(i -> c.compare(toFind, arr[i]) == 0)
157157
.findFirst()
158158
.orElse(-1);
159159
}
160160

161-
}
161+
}

0 commit comments

Comments
 (0)
0