8000 update · githubcs/Java-Coding-Problems@4d5e9b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d5e9b5

Browse files
committed
update
1 parent e83bdba commit 4d5e9b5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

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

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

1515
if (arr == null) {
1616
throw new IllegalArgumentException("Array cannot be null");
@@ -25,7 +25,7 @@ public static boolean findElementV1(int[] arr, int find) {
2525
return false;
2626
}
2727

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

3030
if (arr == null) {
3131
throw new IllegalArgumentException("Array cannot be null");
@@ -37,7 +37,7 @@ public static boolean findElementV2(int[] arr, int find) {
3737
return (index >= 0);
3838
}
3939

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

4242
if (arr == null) {
4343
throw new IllegalArgumentException("Array cannot be null");
@@ -47,7 +47,7 @@ public static boolean findElementV3(int[] arr, int find) {
4747
.anyMatch(e -> e == find);
4848
}
4949

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

5252
if (arr == null || find == null) {
5353
throw new IllegalArgumentException("None of the arguments can be null");
@@ -62,7 +62,7 @@ public static <T> boolean findElementObjectV1(T[] arr, T find) {
6262
return false;
6363
}
6464

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

6767
if (arr == null || find == null || c == null) {
6868
throw new IllegalArgumentException("None of the arguments can be null");
@@ -77,7 +77,7 @@ public static <T> boolean findElementObjectV2(T[] arr, T find, Comparator<? supe
7777
return false;
7878
}
7979

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

8282
if (arr == null || find == null || c == null) {
8383
throw new IllegalArgumentException("None of the arguments can be null");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@ public static void main(String[] args) {
2626

2727
System.out.println("\nSimple solution for numbers:");
2828
long startTimeV1 = clock.millis();
29-
boolean found1 = ArrayFinds.findElementV1(numbers.clone(), 1);
29+
boolean found1 = ArrayFinds.containsElementV1(numbers.clone(), 1);
3030
displayExecutionTime(clock.millis() - startTimeV1);
3131
System.out.println("The element was found?: " + found1);
3232

3333
System.out.println("\nSolution based on Arrays.binarySearch() for numbers:");
3434
long startTimeV2 = clock.millis();
35-
boolean found2 = ArrayFinds.findElementV2(numbers.clone(), 1);
35+
boolean found2 = ArrayFinds.containsElementV2(numbers.clone(), 1);
3636
displayExecutionTime(clock.millis() - startTimeV2);
3737
System.out.println("The element was found?: " + found2);
3838

3939
System.out.println("\nSolution based on Stream.anyMatch() for numbers:");
4040
long startTimeV3 = clock.millis();
41-
boolean found3 = ArrayFinds.findElementV3(numbers.clone(), 1);
41+
boolean found3 = ArrayFinds.containsElementV3(numbers.clone(), 1);
4242
displayExecutionTime(clock.millis() - startTimeV3);
4343
System.out.println("The element was found?: " + found3);
4444

4545
System.out.println("\nSimple solution for Melon:");
4646
long startTimeV4 = clock.millis();
47-
boolean found4 = ArrayFinds.findElementObjectV1(melons.clone(), new Melon("Gac", 1200));
47+
boolean found4 = ArrayFinds.containsElementObjectV1(melons.clone(), new Melon("Gac", 1200));
4848
displayExecutionTime(clock.millis() - startTimeV4);
4949
System.out.println("The Melon was found?: " + found4);
5050

5151
System.out.println("\nSolution based on Comparator for Melon:");
5252
long startTimeV5 = clock.millis();
53-
boolean found5 = ArrayFinds.findElementObjectV2(melons.clone(), new Melon("Gac", 1205), byType);
53+
boolean found5 = ArrayFinds.containsElementObjectV2(melons.clone(), new Melon("Gac", 1205), byType);
5454
displayExecutionTime(clock.millis() - startTimeV5);
5555
System.out.println("The Melon was found?: " + found5);
5656

5757
System.out.println("\nSolution based on binarySearch() for Melon:");
5858
long startTimeV6 = clock.millis();
59-
boolean found6 = ArrayFinds.findElementObjectV3(melons.clone(), new Melon("Honeydew", 1200), byWeight);
59+
boolean found6 = ArrayFinds.containsElementObjectV3(melons.clone(), new Melon("Honeydew", 1200), byWeight);
6060
displayExecutionTime(clock.millis() - startTimeV6);
6161
System.out.println("The Melon was found?: " + found6);
6262

0 commit comments

Comments
 (0)
0