Results 1 to 2 of 2
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default java method with multiple return values

    does java support multiple return statements?I have a method like this where I want to return two to three arraylist,when the method is called..How do i go about doing this,does the code shown below is the right way to return the two arraylist???

    Java Code:
    public ArrayList<String>,ArrayList<String> multiplereturns()
    	{
    		ArrayList<String> al1=new ArrayList<String>();
    		al1.add("1");
    		al1.add("2");
    		
    		ArrayList<String> al2=new ArrayList<String>();
    		al2.add("3");
    		al2.add("4");
    		
    		return al1,al2;
    	}

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Nope it can't ...

    Java doesn't support multiple return statements/values... it can only have one. As a suggestion, you can try to return an array of arraylists. This has also been discussed before:

    [SOLVED] Multiple return values

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. [SOLVED] Multiple return values
    By Manfizy in forum New To Java
    Replies: 17
    Last Post: 05-25-2009, 01:07 PM
  2. accessing return values from another class
    By moaxjlou in forum New To Java
    Replies: 3
    Last Post: 10-31-2008, 03:25 AM
  3. Using functions that return values?
    By Megapixelz in forum New To Java
    Replies: 1
    Last Post: 04-30-2008, 05:07 AM
  4. how to return values from hashmap
    By oregon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:56 PM

Posting Permissions

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