Home / Data structures and Algorithms by Java Examples / Recursion / Recursion on ArrayList Strings in JAVA Example
Recursion on ArrayList Strings in JAVA Example
1013 views.
PrintArrayListStrings.java
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);
    }
}
Output
John
Ram
Kumar
Venkat
Angel
Related Examples
   Simple Recursion Example in JAVA
   Print array using recursion JAVA Example
   Recursion on ArrayList Strings in JAVA Example
   Factorial Program using Recursion in JAVA Example
   Fibonacci Series using Recursion in JAVA Example
   Tree Traversal with Recursion in JAVA Example
   Tree Traversal without Recursion Using Stack Class in JAVA Example
   Is ArrayList Ordered using Recursion in JAVA Example
   Tower of Hanoi using Recursion in Java Example
Copyright © 2016 Learn by Examples, All rights reserved