Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Return all values in an ArrayList from a method

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Return all values in an ArrayList from a method

    Hi guys,

    Would anyone know how to get all values from an ArrayList using a method? I have the following code set up;

    	public Object getList() {
    		for (int j=0; j < test.listArray[start][end].size(); j++) {
    			return test.listArray[start][end].get(j);
    		}
    		return null;
    	}

    This code only returns the first value in the ArrayList as the return null terminates the loop. Is there anyway to get around this?

    I know the code does iterate fine because I have tested it with a System.out.println() snippet but I need it to work within a method.


  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Return all values in an ArrayList from a method

    Can this thread be deleted?

    I've come up with a solution.

Similar Threads

  1. ArrayList recursion return help
    By Twoacross in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2012, 05:51 PM
  2. Need help my values wont return
    By sajeed in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 7th, 2012, 08:46 AM
  3. Return the rgb values from a jpg image
    By newparticipant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 03:47 PM
  4. [SOLVED] How to get the return of a method inside an object in an ArrayList?
    By Hallowed in forum Java Theory & Questions
    Replies: 7
    Last Post: May 1st, 2011, 10:44 PM
  5. ArrayList Unexpected Return
    By Cammack in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2010, 09:23 PM