javaobjectcollectionsarraylist

How to print the contents of ArrayList?


I have a class where I have a ArrayList of Checkbook registered in the same class, I have a method

imprimirTalonario ()

deveria, which prints the record ArrayList, which I'll be working on that

public class Talonario
{
    Boleta bol;
    ArrayList registro = new ArrayList();
    UsaBoleta usaboleta;
    public void imprimirTalonario()
    {
         // Convert ArrayList to Object array
        Object[] elements = registro.toArray();
 
        // Print Object content
        for (int a = 0; a < elements.length; a++) 
        {
            System.out.println(elements[a]);
        }
    }
}

Solution

  • You will need to add elements to ArrayList By default ArrayList is empty

        ArrayList<Integer> registro = new ArrayList<Integer>();
        registro.add(10);