Skip to content

Instantly share code, notes, and snippets.

@ahmadmust8
Last active September 7, 2016 23:33
Show Gist options
  • Save ahmadmust8/0de6b4f78ff0494b098b3cd2a65445f8 to your computer and use it in GitHub Desktop.
Save ahmadmust8/0de6b4f78ff0494b098b3cd2a65445f8 to your computer and use it in GitHub Desktop.
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"
}
}
@ahmadmust8
Copy link
Author

this method for search in ArrayList of type "String".
you can change the type to any other type like "Integer" , "Double"....etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment