mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 23:13:57 -05:00
Added isFound function
This commit is contained in:
@@ -25,7 +25,6 @@ Copyright (C) 2019 Matthew Ellison
|
||||
package mattrixwv;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -730,4 +729,37 @@ public class Algorithms{
|
||||
//Return the product of all elements
|
||||
return product;
|
||||
}
|
||||
public static Boolean isFound(ArrayList<Integer> ary, Integer key){
|
||||
//Look through every element in the array, looing for the key element
|
||||
for(Integer num : ary){
|
||||
//If there is an element in the array that is the same as key return true
|
||||
if(num == key){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//If you made it to the end of the array without finding a match return false because the element was not found
|
||||
return false;
|
||||
}
|
||||
public static Boolean isLongFound(ArrayList<Long> ary, Long key){
|
||||
//Look through every element in the array, looing for the key element
|
||||
for(Long num : ary){
|
||||
//If there is an element in the array that is the same as key return true
|
||||
if(num == key){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//If you made it to the end of the array without finding a match return false because the element was not found
|
||||
return false;
|
||||
}
|
||||
public static Boolean isBigFound(ArrayList<BigInteger> ary, BigInteger key){
|
||||
//Look through every element in the array, looing for the key element
|
||||
for(BigInteger num : ary){
|
||||
//If there is an element in the array that is the same as key return true
|
||||
if(num == key){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//If you made it to the end of the array without finding a match return false because the element was not found
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user