Results 1 to 2 of 2
  1. #1
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default problem with storing the returned values in an array

    hi, i want to store every returned value from the methods mentioned below in an array "array", but the problem is, there is one method
    returns an array. please guide me

    Java Code:
    package ProjectTest;
    import java.util.Random;
    public class GenerateRandomQues {
    	public void randomise(Group [][]group, int level)
    		Random rand = new Random();
    		int randIndex = rand.nextInt(3);
                   int[] array = new int[5];
    		group[randIndex][level].getGroupIndex();// 1
    		group[randIndex][level].getGroupDiff();// 2
    		group[randIndex][level].getGroupQues();// 3
    		group[randIndex][level].getGroupOptions();// 4 this method returns array of options options[]
    		group[randIndex][level].getGroupAnswer();// 5

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: problem with storing the returned values in an array

    If the method returns an array you cannot store it as an element of an array of int. Only int values can be stored in an array of int.

    You might think about:

    * Storing the returned things in an array of something else, like Object. Which is yukky because the whole point of declaring an array to have elements of some specific type is that it will have elements of a specific type.
    * Don't store the returned values in an array, instead store them in an instance of some class you define to hold index, diff, question, options and answer. Without knowing anything else this would be my preferred approach.
    * Have helper methods that will translate between an array of options and an int. Tricky and only possible if the number of possible arrays of options is rather limited.

Similar Threads

  1. XML read and storing values
    By LiveStrong-2011 in forum New To Java
    Replies: 1
    Last Post: 05-31-2011, 12:04 PM
  2. Problem returning Array values Please help
    By drgnfire25 in forum New To Java
    Replies: 4
    Last Post: 01-12-2011, 01:53 AM
  3. Replies: 2
    Last Post: 10-28-2010, 03:33 PM
  4. question on how to check values before storing
    By SMHouston in forum New To Java
    Replies: 19
    Last Post: 09-21-2009, 11:54 PM
  5. Cant we have two values returned from a method in a class
    By jaiminparikh in forum Advanced Java
    Replies: 7
    Last Post: 03-21-2009, 04:20 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