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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:29:10+00:00 2026-05-31T21:29:10+00:00

Basically I have an ArrayList of locations: ArrayList<WorldLocation> locations = new ArrayList<WorldLocation>(); below this

  • 0

Basically I have an ArrayList of locations:

ArrayList<WorldLocation> locations = new ArrayList<WorldLocation>();

below this I call the following method:

.getMap();

the parameters in the getMap() method are:

getMap(WorldLocation... locations)

The problem I’m having is I’m not sure how to pass in the WHOLE list of locations into that method.

I’ve tried

.getMap(locations.toArray())

but getMap doesn’t accept that because it doesn’t accept Objects[].

Now if I use

.getMap(locations.get(0));

it will work perfectly… but I need to somehow pass in ALL of the locations… I could of course make keep adding locations.get(1), locations.get(2) etc. but the size of the array varies. I’m just not use to the whole concept of an ArrayList

What would be the easiest way to go about this? I feel like I’m just not thinking straight right now.

  • 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-05-31T21:29:11+00:00Added an answer on May 31, 2026 at 9:29 pm

    Source article: Passing a list as an argument to a vararg method


    Use the toArray(T[] arr) method.

    .getMap(locations.toArray(new WorldLocation[0]))
    

    Here’s a complete example:

    public static void method(String... strs) {
        for (String s : strs)
            System.out.println(s);
    }
    
    ...
        List<String> strs = new ArrayList<String>();
        strs.add("hello");
        strs.add("world");
        
        method(strs.toArray(new String[0]));
        //     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: private <E extends Number> void AddOne(ArrayList<E> al, Double num)
I have the following problem when using java generic. Basically I need to do
I am using java/blazeds/flex. So basically I have method in java: public ArrayList<Employee> getAllEmployees(){
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have the same question as this guy .. The example in the
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I have a class, the outline of which is basically listed below. import org.apache.commons.math.stat.Frequency;
I have a simple test project in Spring 3, basically a method within the

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.