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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:14:43+00:00 2026-05-19T04:14:43+00:00

Assume a method with the following signature: public static void foo(String arg1, String args2,

  • 0

Assume a method with the following signature:

public static void foo(String arg1, String args2, Object... moreArgs);

When running …

ClassName.foo("something", "something", "first", "second", "third");

… I’ll get moreArgs[0] == "first", moreArgs[1] == "second" and moreArgs[2] == "third".

But assume that I have the parameters stored in an ArrayList<String> called arrayList which contains “first”, “second” and “third”.

I want to call foo so that moreArgs[0] == "first", moreArgs[1] == "second" and moreArgs[2] == "third" using the arrayList as a parameter.

My naïve attempt was …

ClassName.foo("something", "something", arrayList);

… but that will give me moreArgs[0] == arrayList which is not what I wanted.

What is the correct way to pass arrayList to the foo method above so that moreArgs[0] == "first", moreArgs[1] == "second" and moreArgs[2] == "third"?

Please note that the number of arguments in arrayList happens to be three in this specific case, but the solution I’m looking for should obviously be general and work for any number of arguments in arrayList.

  • 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-19T04:14:43+00:00Added an answer on May 19, 2026 at 4:14 am

    Convert your ArrayList into an Array of type object.

    ClassName.foo("something", "something", arrayList.toArray());
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a method/function with the following signature: foo($bar = 0) Inside foo
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
Lets assume we have the following array var arr = new string[] {foo,bar,jar,\r,a,b,c,\r,x,y,z,\r); Also
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
Assume you are doing something like the following List<string> myitems = new List<string> {
Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new
Let's assume we have the following class : public class ImageButton extends MovieClip {
(assume php5) consider <?php $foo = 'some words'; //case 1 print these are $foo;
Assume that we have N erlang nodes, running same application. I want to share
Assume I have a class foo, and wish to use a std::map to store

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.