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 9004291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:51:59+00:00 2026-06-16T00:51:59+00:00

I have a method that returns an ArrayList of Objects. I return the arraylist

  • 0

I have a method that returns an ArrayList of Objects. I return the arraylist created, and its filled with many objects, that I check they are there by printing them in the same method. When I use that Arraylist as parameter in another method, it gives me an error, like if the arraylist were empty.

Lets say the object its Position(y,x), with methods getFila and getColumna.
And the method that fails (actually does nothing):

public static ArrayList<Position> getTrayectory (ArrayList<Position> aListPos){
        for (int ii = 0; ii < aListPos.size();ii++ ) {
            System.out.println("(" +  aListPos.get(ii).getFila() + "," + aListPos.get(ii).getColumna()+")");
        }
        return aListPos;
    }

I return the Arraylist with many objects inside, but I dont know what is happening with that.

Summary:

1- I have a method that returns an ArryList
2- I create a new Arraylist with method in 1
3- I use new method with Arraylist in 2 as parameter.

(4-) Nothing happens, because new arraylist in 2 look empty.

Can anyone help me in the process?

  • 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-06-16T00:52:00+00:00Added an answer on June 16, 2026 at 12:52 am

    If you are creating the ArrayList in the (unseen) method that provides it, are you returning it? Or are you modifying a parameter?

    In other words, are you doing this:

    ArrayList<Position> myArrayList = generateArrayList(); // or whatever you call it
    

    or are you doing this:

    ArrayList<Position> myArrayList;
    generateArrayList(myArrayList);
    ArrayList<Position> result = getTrayjectory(myArrayList);
    

    The second version of this won’t work, because when you create an object inside a method, the only way that it can escape the method’s bounds is to be returned by that method. Otherwise, it goes out of scope when the method ends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>> , but some of the
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returns module path of given class name def findModulePath(path, className):
I have a method that returns a list of type string. I want to
I have a method that returns lot of data, should I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for
I have a method that returns a new list (it pertains to a multiple
Scenario I have a method that returns a list of processes using WMI. If
All, I have a method that returns a List. This method is used to
I have a site in multiple languages. I have a method that returns me
I have the following method that returns void and I need to use it

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.