Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:52:05+00:00 2026-05-14T02:52:05+00:00

I tried making a wrapper class that encapsulates an object, a string (for naming

  • 0

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();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:52:05+00:00Added an answer on May 14, 2026 at 2:52 am

    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:

    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Random;
    
    class MyClass
    {
        public String name;
        public int[] myIntArray;
    
        public MyClass()
        {
            myIntArray = new int[10];
        }
    }
    
    public class Program
    {
        static final int MAX_RANDOM = 20;
    
        public static void main(String[] args)
        {
            // Create a new map which will use keys of type String and
            // hold values of type MyClass.
            HashMap<String, MyClass> map = new HashMap<String, MyClass>();
    
            // Initialize a new random object. Not supplying a seed number
            // means that it seeds from the system clock, a good source of
            // randomness.
            Random rand = new Random();
    
            // Loop ten times...
            for (int i = 0; i < 10; ++i)
            {
                // ...and each time, create a new MyClass and call it "m"...
                MyClass m = new MyClass();
    
                // ...and set m.name as "c" followed by the iteration number.
                m.name = "c" + i;
    
                // Loop as many times as there are elements in m.myIntArray...
                for (int j = 0; j < m.myIntArray.length; ++j)
                {
                    // ...and each time, set the next element to a new random int
                    // with a value between 0 and MAX_RANDOM.
                    m.myIntArray[j] = rand.nextInt(MAX_RANDOM);
                }
    
                // Once we've filled all the variables, push the object into
                // the map using its name as the lookup key.
                map.put(m.name, m);
    
                // The "m" variable now goes out of scope and the name can be
                // re-used on the next iteration of the loop. "map" and "rand"
                // stay in scope because they were declared outside the loop body.
            }
    
            // Now that we've created ten objects, time to read them back out.
    
            // Get an iterator object which will let us traverse the set of
            // keys (names) in the map.
            Iterator<String> i = map.keySet().iterator();
            // While i still has more keys in the set...
            while (i.hasNext())
            {
                // Grab the next name from the iterator and assign it to
                // a local variable called "name".
                String name = i.next();
    
                // Fetch the instance of MyClass from the map that corresponds
                // to the key (name) we've just grabbed.
                MyClass m = map.get(name);
    
                // Print its name to the console...
                System.out.println("Name: " + m.name);
    
                // Print an opening bracket for the array...
                System.out.print("[");
                // ...and now run through each of the integers in the array
                // and print those out, too.
                for (int j = 0; j < m.myIntArray.length; ++j)
                {
                    // Print the integer at position j...
                    System.out.print(m.myIntArray[j]);
                    // ...and if it's not the last item in the array,
                    // print a comma to separate it from the next one.
                    if (j < m.myIntArray.length - 1) System.out.print(", ");
                }
                // Print the closing bracket, followed by two newlines to
                // separate the next class with whitespace.
                System.out.println("]\n");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone managed to do this? I tried making a managed wrapper class for
I've tried making a global array that can add and remove items across all
Ok, I am making a wrapper of a class that has very long path
I'm writing an app for WM that handles incoming SMS events. I tried making
Hey, So I am new to Android and tried to implement a class that
I am trying to sort array/lists/whatever of data based upon the unicode string values
I'm making a free Mac app that is simply a wrapper over the purge
I tried making registry changes by running WScript that runs reg , but it
Using J2SE, I tried making a LAN application using java.net.*, and it worked perfectly.
I'm making the script for easy upload many files. I've tried fyneworks plugin ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.