Added Array util class
This commit is contained in:
parent
19cca61417
commit
9f95258734
1 changed files with 20 additions and 0 deletions
20
src/zutil/ArrayUtil.java
Executable file
20
src/zutil/ArrayUtil.java
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
package zutil;
|
||||
|
||||
/**
|
||||
* A utility class containing Array specific utility methods
|
||||
*/
|
||||
public class ArrayUtil {
|
||||
|
||||
/**
|
||||
* Searches for a given object inside of an array.
|
||||
* The method uses reference comparison or {@link #equals(Object)} to check for equality.
|
||||
*
|
||||
* @return True if the given Object is found inside the array, false otherwise.
|
||||
*/
|
||||
public static <T> boolean contains(T[] array, T obj) {
|
||||
for (final T element : array)
|
||||
if (element == obj || obj != null && obj.equals(element))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue