Hubert Hubert Hubert Hubert - 4 months ago 6
Android Question

How to add object to array in the other class, Java

This is my code:

public class One
{
//Loots is a class
public static Loots[] lootsList = new Loots[] { };
}

public class Two
{
Loots MyLoots = new Loots();
// How to add in THIS class, MyLoots to lootsList?
}


Please help me.

I don't want to using List!

Answer

Accessing Static variable and method of another class

ClassName.StaticVariable;

OR

ClassName.StaticMethod;

use this

public class One
    {
       public static Loots[] lootsList = new Loots[1];
    }   

    public class Two
    { 
       Loots MyLoots = new Loots();         
       // How to add in THIS class, MyLoots to lootsList? 
       One.Loots[0]=MyLoots; //use this to access array of objects
    }

enjoy coding .........

Comments