how to create an arraylist of a class that has another arraylist as parameter?

Asked

Viewed 234 times

-2

public class Entra extends Fluxo {
private int periodo;
private boolean fixo;
public static ArrayList<String> prods = new ArrayList<>();
public static ArrayList<Entra> entra = new ArrayList<>();


public Entra(Date data, double valor, String desc, int periodo, ArrayList<String> prods, boolean fixo) {
    super(data, valor, desc);
    this.periodo = periodo;
    Entra.prods = prods;
}

public int getPeriodo() {return periodo;}
public boolean isFixo() {return fixo;}
public static ArrayList<String> getProds() {return prods;}
public static ArrayList<Entra> getEntra() {return entra;}

public void setProds(ArrayList<String> prods) {Entra.prods = prods;}
public static void setEntra(ArrayList<Entra> entra) {Entra.entra = entra;}
public void setPeriodo(int periodo) {this.periodo = periodo;}
public void setFixo(boolean fixo) {this.fixo = fixo;}

1 answer

1


Class Entra:

package org.example;

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

public class Entra extends Fluxo {
    private int periodo;
    private boolean fixo;
    public List<String> prods = new ArrayList<>();
    public List<Entra> entra = new ArrayList<>();

    public Entra(Date data, double valor, String desc, int periodo, List<String> prods, boolean fixo) {
        super(data, valor, desc);
        this.periodo = periodo;
        this.prods = prods;
    }

    public int getPeriodo() {
        return periodo;
    }

    public boolean isFixo() {
        return fixo;
    }

    public List<String> getProds() {
        return prods;
    }

    public List<Entra> getEntra() {
        return entra;
    }

    public void setProds(List<String> prods) {
        this.prods = prods;
    }

    public void setEntra(List<Entra> entra) {
        this.entra = entra;
    }

    public void setPeriodo(int periodo) {
        this.periodo = periodo;
    }

    public void setFixo(boolean fixo) {
        this.fixo = fixo;
    }
}

Main class

package org.example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        List<String> prods = Arrays.asList("p1", "p2");
        Entra entra = new Entra(new Date(), 0.0, "teste", 0, prods, true);

        List<Entra> lista = new ArrayList<>(Arrays.asList(entra));
    }

}

Browser other questions tagged

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