Results 1 to 5 of 5
  1. #1
    Jtrtoday is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default How to Store an Array in an Array

    I have a function called readRecords that returns an array I want to store the array it returns in another array how would I got about doing this? or is there a better way to solve the problem?

    Java Code:
    private static void Display (int[] Gold, String[] Name) {
    		int LeftOver = 0;
    		int i = 0;
    		ReadRecords file = new ReadRecords();
    		Items contents = new Items();
    		while(i < Name.length){
    			String[] Temp= file.readRecords(Name[i]);
    	  		int X = contents.Random(Gold[i],Temp);
    	  		LeftOver += X;
       	 	System.out.printf("\nLeft over: "+ LeftOver + "\n");
    This is what I'm trying right now, but when String[] Temp gets the second array it doesn't set its self to it it just keeps the contents from the first array it was given.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: How to Store an Array in an Array

    I'm a bit confused.
    What do you see and what do you expect to see?

    Whatever the answer is I suggest you stick some debugging code in there to show what exactly is going on.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    aianta is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Re: How to Store an Array in an Array

    Consider using a 2d array maybe? Not sure if this is what you asked for but, you could have each cell in your array be stored in one "row" of the 2d array.

  4. #4
    awinston is offline Student
    Join Date
    Jul 2012
    United States
    Rep Power

    Default Re: How to Store an Array in an Array

    A String[] will hold String objects. It will not hold an array of Strings.

    As aianta suggested, it looks like you want to use a 2-dimensional array. If you want an array that holds arrays of Strings, you would want String[][].
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  5. #5
    fultonwilcox is offline Member
    Join Date
    Sep 2012
    Rep Power

    Default Re: How to Store an Array in an Array

    awinston is right. int[][] would be an array of arrays. imagine lining up int[] as a column. the second [] would make it expand to the right.

    a b c d
    e f g h
    i j k l
    m n o p

    to access p, it would be something like array[4][4]

Similar Threads

  1. Store image in an 2D array
    By zenitis in forum New To Java
    Replies: 5
    Last Post: 12-23-2011, 03:53 PM
  2. To store a String in an Array[HELP]
    By djscorpio99 in forum New To Java
    Replies: 2
    Last Post: 08-31-2011, 10:01 AM
  3. how to store data in array
    By aconti in forum New To Java
    Replies: 7
    Last Post: 06-18-2011, 06:24 PM
  4. HOw to Store Data in An Array
    By deshmukh.niraj04 in forum New To Java
    Replies: 4
    Last Post: 04-06-2011, 04:00 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts