Permalink
Browse files

ArrayTricks with string and int finder

  • Loading branch information...
1 parent f301565 commit 5d994f57c258c21cf0f75d0147b125d4848ce58f @sd committed Sep 8, 2011
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/appmonk/tricks/ArrayTricks.java
@@ -0,0 +1,21 @@
+package appmonk.tricks;
+
+public class ArrayTricks {
+ public static int findInt(int [] array, int value) {
+ int l = array.length;
+ for (int i = 0; i < l; i++) {
+ if (array[i] == value)
+ return i;
+ }
+ return -1;
+ }
+
+ public static int findString(String [] array, String value) {
+ int l = array.length;
+ for (int i = 0; i < l; i++) {
+ if (array[i] != null && array[i].equals(value))
+ return i;
+ }
+ return -1;
+ }
+}

0 comments on commit 5d994f5

Please sign in to comment.