Last active
September 7, 2016 23:33
-
-
Save ahmadmust8/0de6b4f78ff0494b098b3cd2a65445f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Test_some_thing; | |
import java.util.ArrayList; | |
/** | |
* @author ahmad alalwi | |
*/ | |
public class search_In_ArrayList | |
{ | |
public boolean SearchInArray(ArrayList<String> arrayList,String searcher) | |
{ | |
try { | |
//get String for searching in array if it's elements of array or not ? | |
// assignment the array index number to to "indexNumber" | |
int indexNumber = arrayList.indexOf(searcher); | |
//exam the array if have String equals "searcher" | |
if(searcher.equals(arrayList.get(indexNumber))==true) | |
//if array have string equals "searcher" | |
return true; | |
} | |
catch (ArrayIndexOutOfBoundsException exception) | |
{ | |
System.err.println(exception.getMessage().toString()); | |
} | |
return false;//if array no have like "searcher" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this method for search in ArrayList of type "String".
you can change the type to any other type like "Integer" , "Double"....etc.