Arraylist of classes

Asked

Viewed 58 times

-2

I have a main class that has auxiliary classes as attributes.

Example: Main class MoedasList:

public class MoedasList {
    public USD USD;
    public USDT USDT;
    public ARS ARS;
}

Each attribute is an auxiliary class with its individual attributes.

Example: Auxiliary class USD:

public class USD {
    public String code;           //": "BRL",
    public String codein;         //": "BRL",
    public String name;           //": "Dólar Comercial",
    public String high;           //": "3,9766",
    public String low;            //": "3,9748",
    public String varBid;         //": "0,0021",
    public String pctChange;      //: "0,05",
    public String bid;            //": "3,9765",
    public String ask;            //": "3,9767",
    public String timestamp;      //": "1557873008",
    public String create_date;    //": "2019-05-14 21:00:05"
}

How I ride one ArrayList of the main class MoedasList?

I assembled the class this way to receive the data from a JSON.

I get the normal data, but now I’d like to assemble a ArrayList.

  • Friend, it’s hard to know what you want to do. Try to explain your need better please.

  • i would like to return a list with all the attributes of the Moedalist class, and the atripipes of the Moedalis class are all separate classes with the Specification of each coin, with its attributes

1 answer

0

If the ArrayList is of class MoedasList, you can do

MoedasList[] moedas = new MoedasList[n];

where n is the number of items on the list.

Then you need to start the objects of this class.

moedas[0] = new MoedasList();

If you want to start all the objects in the list, you can do

for (int i = 0; i < moedas.length; i++){
    moedas[i] = new MoedasList();
}
  • this I will have to start all the elements, and show on an input screen. Each element started, attribute, is a class of each specific currency with its attributes, value type, etc.. then when creating the list you should show each attribute of the Moedalist class and also display the values attributes, etc of each currency.

  • conequi access the attributes but it is a bidimenssional array

Browser other questions tagged

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