package Recursion; import java.util.*; public class AListRecursiveSearch { private static final String colors[] = { "black", "yellow", "green", "blue", "violet", "silver" }; ArrayList aList; public AListRecursiveSearch(){ aList = new ArrayList(); for ( int count = 0; count < colors.length; count++ ) aList.add( colors[ count ] ); if(search("green", 0))//explain in details System.out.println("green is found in the list"); else System.out.println("green is not found in the list"); if(search("magenta", 0))//explain in details System.out.println("magenta is found in the list"); else System.out.println("magenta is not found in the list"); } public boolean search(String str, int nextIndex){ if(aList.size()==nextIndex) return false; else if(aList.get(nextIndex).equals(str)) return true; else return search(str, ++nextIndex); } public static void main( String args[] ) { new AListRecursiveSearch(); } } // end class AListRecursiveSearch