Results 1 to 4 of 4
  1. #1
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default Error in the "join" method of StringUtils

    Hi,

    I have a problem with the following code:
    -------------------------------------------------------------------

    public static String createItemList (Collection<String> _items)
    {
    if (_items == null || _items.isEmpty ())
    {
    return "";
    }
    else
    {
    return "'" + StringUtils.join (_items, "','") + "'"; }
    }

    ---------------------------------------------------------------------
    The bolded line in the above code causing an error: " The method join(Object[], String) in the type StringUtils is not applicable for the arguments (Collection<String>, String) "

    String Utils already have the method " join(Collection collection, String string), i confirmed that. But Still i got the same error.
    Can anyone help me in solving this error.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    You need to pass it an array not a list.

  3. #3
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi masijade, I cant get u. Can u explain with the actual code

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    You are calling join with a Collection as the first argument and you should be calling it with an array as the first argument (see the API docs for Collection and it's toArray method). And no, I cannot "explain with code" I am not here to do your work for you. I told you what you are doing wrong (and the exception did too if you would actually read it) and gave you a hint on how to fix it. Now, it is up to you to at least try to do it.

Similar Threads

  1. Replies: 10
    Last Post: 12-07-2010, 12:29 PM
  2. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  3. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  4. Replies: 6
    Last Post: 10-27-2008, 12:25 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •