I tried making a wrapper class that encapsulates an object, a string (for naming and differentiating the object instance), and an array to store data. The problem I’m having now is accessing this class using methods that determine the “name” of the object and also reading the array containing some random variables.
Note: This was edited from the original but the code below it is better anyways.
import java.util.Arrays;
import java.util.Random;
public class WrapperClass
{
String varName;
Object varData;
int[] array = new int[10];
static WrapperClass globalobject;
public WrapperClass(String name, Object data, int[] ARRAY)
{
varName = name;
varData = data;
array = ARRAY;
}
public static void getvalues()
{
}
public static void main(String[] args)
{
Random random = new Random(3134234);
String x;
Object y;
int[] n = new int[10];
WrapperClass object;
for(int i = 0; i < 10; i++)
{
int[] array = new int[10];
for (int c = 0; c < 10; c++)
{
array[c] = random.nextInt();//randomly creates data
}
globalobject = new WrapperClass("c" + i, new Object(),array);
}
globalobject.getvalues();
}
}
Okay, I went ahead and took a look at the post you linked in the comment and now I think I understand why you’re trying to do this. This seems to be a communication problem, for the most part — I think you have an idea of what you’re trying to do in conceptual terms but from what I gather you’re new to OOP and having difficulty expressing it in technical terms.
Essentially, what you want to do here is to take some arbitrary data of some sort, stuff it away using a name, and then get it back using that name in the future, right?
Java has a structure called a map which will let you do exactly this, without needing to worry about wrappers or other structures. Here’s a heavily-commented example of how to use a map which should hopefully help clear up some of your confusion: