How to print the contents of an Object in a List<>

Asked

Viewed 125 times

0

I am developing a JAVA application in which will display the contents of an object in a list. My goal is to print the object content of a list.

package teste1;

import java.util.ArrayList;
import java.util.List;

import teste1.ProductMovement;



public class Teste {

    private List<ProductMovement> filterFractionedMovements(List<ProductMovement> reservMovements) {

        return reservMovements;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         // Creating a list 


        List<ProductMovement> pro = new ArrayList<ProductMovement>();
        ProductMovement p = new ProductMovement();

        p.setId(1);
        p.setNome("Teste1");
        pro.add(0,p);

      System.out.println( ??????);

    }
}

I have to display the contents here in this section:

System.out.println( ??????);

Code Productmovement:

package teste1;

public class ProductMovement {
    private int id;
    private String nome;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }

}
  • We also do not know what you want to print, the problem is to take the element from the list or print the object? They are two different things.

  • print the object

  • System.out.println(pro.get(0). getName());

  • I managed to just add this

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.