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

  • Home
  • SEARCH
  • 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 a method declared as the following: public static string GetString<T>(IEnumerable<T> collection, string theProperty)
Consider the following static method: public void static foo() { // some heavy operation
Assume I have a method/function with the following signature: foo($bar = 0) Inside foo
I have to assume that the following method doesn't leak memory: public final void
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
Assume the following scenario. i call a method like this String[] arr = {1,2,3};
Let's assume we have the following method in the business layer. What's the best
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have a method with the signature: + (NSString *) myFormattedString:(NSString *)format, ...;
Assume the following problem context: 1) In our application, we have a business object

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.