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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:57:43+00:00 2026-05-31T17:57:43+00:00

I am attempting to call the Apache Commons StringUtils.join() method from within a Groovy

  • 0

I am attempting to call the Apache Commons StringUtils.join() method from within a Groovy class. I want to concatenate 3 strings (part1, part2, and part3).

Why doesn’t this work?

def path = StringUtils.join([part1, part2, part3]) //1

But the following line works:

def path = StringUtils.join([part1, part2, part3] as String[]) //2

A follow up question. Why does this work? I am using StringUtils v 2.6, so it does not have a varargs method. Does groovy always convert method parameters to an array?

def path = StringUtils.join(part1, part2, part3)  //3

This is largely a curiosity question. I am not going to use StringUtils because I posted a separate question yesterday and found a better solution. However, I would still like to understand why technique #1 does not work, yet #3 does work.

  • 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-31T17:57:44+00:00Added an answer on May 31, 2026 at 5:57 pm

    So, to show what is happening, let’s write a script and show what output we get:

    @Grab( 'commons-lang:commons-lang:2.6' )
    import org.apache.commons.lang.StringUtils
    
    def (part1,part2,part3) = [ 'one', 'two', 'three' ]
    
    def path = StringUtils.join( [ part1, part2, part3 ] )
    println "1) $path"
    
    path = StringUtils.join( [ part1, part2, part3 ] as String[] )
    println "2) $path"
    
    path = StringUtils.join( part1, part2, part3 )
    println "3) $path"
    

    This prints:

    1) [one, two, three]
    2) onetwothree
    3) onetwothree
    

    Basically, the only one of your method calls that matches a signature in the StringUtils class is 2), as it matches the Object[] method definition. For the other two, Groovy is picking the best match that is can find for your method call.

    For both 1) and 3), it’s doing the same thing. Wrapping the parameters as an Object[] and calling the same method as 2)

    For 3) this is fine, as you get an Object[] with 3 elements, but for 1), you get an Object[] with one element; your List.

    A way of getting it to work with the List parameter, would be to use the spread operator like so:

    path = StringUtils.join( *[ part1, part2, part3 ] )
    println "4) $path"
    

    Which would then print:

    4) onetwothree
    

    As expected (it would put all the elements of the list in as separate parameters, and these would then be put into an Object[] with three elements as in example 3)

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

Sidebar

Related Questions

This is my first time attempting to call an ASP.NET page method from jQuery.
I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code
I'm attempting to call a method which is outside the class I'm working in
I'm attempting to call a constructor method that looks like: public static SomeWrapper<T> method(Class<T>
I'm using ASP.NET and attempting to call a method with a signature of [WebMethod]
I am attempting to call an ASP.NET page from a classic ASP page on
I am getting an error when attempting to call a stored proc from my
I am attempting to call ffmpeg to create an image from a frame in
I am attempting to call a C++ API from python. Following is the code
I'm attempting to call a PHP script from a C++ program. For instance, here

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.