Wrapper class that creates objects at runtime and stores data in an array.

Posted by scriptingalias on Stack Overflow See other posts from Stack Overflow or by scriptingalias
Published on 2010-04-03T10:53:15Z Indexed on 2010/04/03 11:03 UTC
Read the original article Hit count: 245

Filed under:
|

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.

import java.util.Arrays;
import java.util.Random;

public class WrapperClass
{
    String varName;
    Object varData;
    int[] array = new int[10];
    public WrapperClass(String name, Object data, int[] ARRAY)
    {
        varName = name;
        varData = data;
        array = ARRAY;
    }
    public static void getvalues()
    {

    }
    public static void main(String[] args)
    {
       int[] array = new int[10];
       Random random = new Random(3134234);

       for(int i = 0; i < 10; i++)
       {
        for (int c = 0; c < 10; c++)
        {
            array[c] = random.nextInt();//randomly creates data
        }
        WrapperClass w = new WrapperClass("c" + i, new Object(),array);
       }     
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays