How To Print An Array List In Java Code Example

Snippet 1
  // Java program to demonstrate the 
// working of ArrayList in Java 
  
import java.io.*; 
import java.util.*; 
  
class ArrayListExample { 
    public static void main(String[] args) 
    { 
        // Size of the 
        // ArrayList 
        int n = 5; 
  
        // Declaring the ArrayList with 
        // initial size n 
        ArrayList arrli 
            = new ArrayList(n); 
  
        // Appending new elements at 
        // the end of the list 
        for (int i = 1; i <= n; i++) 
            arrli.add(i); 
  
        // Printing elements 
        System.out.println(arrli); 
  
        // Remove element at index 3 
        arrli.remove(3); 
  
        // Displaying the ArrayList 
        // after deletion 
        System.out.println(arrli); 
  
        // Printing elements one by one 
        for (int i = 0; i < arrli.size(); i++) 
            System.out.print(arrli.get(i) + " "); 
    } 
} 
 
Snippet 2
  Arrays.toString(list.toArray()) 

Similar Snippets


Create Copy Of Array From Another Array Code Example - java

Creating Java Main Method Code Example - java

Find Duplicates In Arraylist Java Code Example - java

Java Creat A Folder Code Example - java

Firestore Find Doc And Set Data Code Example - java