Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1437

Remove redundant if statements in StringUtils.join

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.6
    • None
    • None
    • None

    Description

      In the various join methods in StringUtils, the for-loop contains an if (i > startIndex) check (for an example see here, but it's present in all the join methods that take an array).
      That is unnecessary - for the first iteration, we know the condition is false, while for the other iterations, we know the condition is true. So instead, we can do this:

      • append the first element (at position startIndex)
      • for every other element (starting at position startIndex + 1), append the separator, then the element.

      It's basically the same tactic used in the Iterable version.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            aft90 Andrei Filip Troie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m

                Slack

                  Issue deployment