4665 views.
import java.util.ArrayList;
class PrintArrayListStrings {
public static void display(ArrayList<String> list,int index) {
//if index != -1 then trying to display string from array list.
if (index != -1) {
//calling for previous element using index - 1
display(list,index - 1);
//printing current index string.
System.out.println(list.get(index));
}
}
public static void main(String[] args) {
//Creating arraylist list object.
ArrayList<String> list = new ArrayList<String>();
//Adding person names to list.
list.add("John");
list.add("Ram");
list.add("Kumar");
list.add("Venkat");
list.add("Angel");
//To display array of
display(list,list.size() - 1);
}
}