@@ -10,152 +10,152 @@ private ArrayFinds() {
10
10
throw new AssertionError ("Cannot be instantiated" );
11
11
}
12
12
13
- public static boolean containsElementV1 (int [] arr , int find ) {
13
+ public static boolean containsElementV1 (int [] arr , int toContain ) {
14
14
15
15
if (arr == null ) {
16
16
throw new IllegalArgumentException ("Array cannot be null" );
17
17
}
18
18
19
19
for (int elem : arr ) {
20
- if (elem == find ) {
20
+ if (elem == toContain ) {
21
21
return true ;
22
22
}
23
23
}
24
24
25
25
return false ;
26
26
}
27
27
28
- public static boolean containsElementV2 (int [] arr , int find ) {
28
+ public static boolean containsElementV2 (int [] arr , int toContain ) {
29
29
30
30
if (arr == null ) {
31
31
throw new IllegalArgumentException ("Array cannot be null" );
32
32
}
33
33
34
34
Arrays .sort (arr );
35
- int index = Arrays .binarySearch (arr , find );
35
+ int index = Arrays .binarySearch (arr , toContain );
36
36
37
37
return (index >= 0 );
10000
38
38
}
39
39
40
- public static boolean containsElementV3 (int [] arr , int find ) {
40
+ public static boolean containsElementV3 (int [] arr , int toContain ) {
41
41
42
42
if (arr == null ) {
43
43
throw new IllegalArgumentException ("Array cannot be null" );
44
44
}
45
45
46
46
return Arrays .stream (arr )
47
- .anyMatch (e -> e == find );
47
+ .anyMatch (e -> e == toContain );
48
48
}
49
49
50
- public static <T > boolean containsElementObjectV1 (T [] arr , T find ) {
50
+ public static <T > boolean containsElementObjectV1 (T [] arr , T toContain ) {
51
51
52
- if (arr == null || find == null ) {
52
+ if (arr == null || toContain == null ) {
53
53
throw new IllegalArgumentException ("None of the arguments can be null" );
54
54
}
55
55
56
56
for (T elem : arr ) {
57
- if (elem .equals (find )) {
57
+ if (elem .equals (toContain )) {
58
58
return true ;
59
59
}
60
60
}
61
61
62
62
return false ;
63
63
}
64
64
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 ) {
66
66
67
- if (arr == null || find == null || c == null ) {
67
+ if (arr == null || toContain == null || c == null ) {
68
68
throw new IllegalArgumentException ("None of the arguments can be null" );
69
69
}
70
70
71
71
for (T elem : arr ) {
72
- if (c .compare (elem , find ) == 0 ) {
72
+ if (c .compare (elem , toContain ) == 0 ) {
73
73
return true ;
74
74
}
75
75
}
76
76
77
77
return false ;
78
78
}
79
79
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 ) {
81
81
82
- if (arr == null || find == null || c == null ) {
82
+ if (arr == null || toContain == null || c == null ) {
83
83
throw new IllegalArgumentException ("None of the arguments can be null" );
84
84
}
85
85
86
86
Arrays .sort (arr , c );
87
- int index = Arrays .binarySearch (arr , find , c );
87
+ int index = Arrays .binarySearch (arr , toContain , c );
88
88
89
89
return (index >= 0 );
90
90
}
91
91
92
- public static int findIndexOfElementV1 (int [] arr , int find ) {
92
+ public static int findIndexOfElementV1 (int [] arr , int toFind ) {
93
93
94
94
if (arr == null ) {
95
95
throw new IllegalArgumentException ("Array cannot be null" );
96
96
}
97
97
98
98
for (int i = 0 ; i < arr .length ; i ++) {
99
- if (arr [i ] == find ) {
99
+ if (arr [i ] == toFind ) {
100
100
return i ;
101
101
}
102
102
}
103
103
104
104
return -1 ;
105
105
}
106
106
107
- public static int findIndexOfElementV2 (int [] arr , int find ) {
107
+ public static int findIndexOfElementV2 (int [] arr , int toFind ) {
108
108
109
109
if (arr == null ) {
110
110
throw new IllegalArgumentException ("Array cannot be null" );
111
111
}
112
112
113
113
return IntStream .range (0 , arr .length )
114
- .filter (i -> find == arr [i ])
114
+ .filter (i -> toFind == arr [i ])
115
115
.findFirst ()
116
116
.orElse (-1 );
117
117
}
118
118
119
- public static <T > int findIndexOfElementObjectV1 (T [] arr , T find ) {
119
+ public static <T > int findIndexOfElementObjectV1 (T [] arr , T toFind ) {
120
120
121
- if (arr == null || find == null ) {
121
+ if (arr == null || toFind == null ) {
122
122
throw new IllegalArgumentException ("None of the arguments can be null" );
123
123
}
124
124
125
125
for (int i = 0 ; i < arr .length ; i ++) {
126
- if (arr [i ].equals (find )) {
126
+ if (arr [i ].equals (toFind )) {
127
127
return i ;
128
128
}
129
129
}
130
130
131
131
return -1 ;
132
132
}
133
133
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 ) {
135
135
136
- if (arr == null || find == null || c == null ) {
136
+ if (arr == null || toFind == null || c == null ) {
137
137
throw new IllegalArgumentException ("None of the arguments can be null" );
138
138
}
139
139
140
140
for (int i = 0 ; i < arr .length ; i ++) {
141
- if (c .compare (arr [i ], find ) == 0 ) {
141
+ if (c .compare (arr [i ], toFind ) == 0 ) {
142
142
return i ;
143
143
}
144
144
}
145
145
146
146
return -1 ;
147
147
}
148
148
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 ) {
150
150
151
- if (arr == null || find == null || c == null ) {
151
+ if (arr == null || toFind == null || c == null ) {
152
152
throw new IllegalArgumentException ("None of the arguments can be null" );
153
153
}
154
154
155
155
return IntStream .range (0 , arr .length )
156
- .filter (i -> c .compare (find , arr [i ]) == 0 )
156
+ .filter (i -> c .compare (toFind , arr [i ]) == 0 )
157
157
.findFirst ()
158
158
.orElse (-1 );
159
159
}
160
160
161
- }
161
+ }
0 commit comments