Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5015163

(str) String merge/join that is the inverse of String.split()

    XMLWordPrintable

Details

    • b89
    • generic, x86
    • generic, windows_xp, windows_7
    • Verified

    Description

      Name: jl125535 Date: 03/17/2004


      A DESCRIPTION OF THE REQUEST :
      The class java.lang.String lacks a facility to merge a String array to a single String with support for a delimiter that's inserted between the array elements. This facility should be the opposite of java.lang.String.split .

      JUSTIFICATION :
      The String merge/join facility is very common thing and can be used in many situations. It would make the life of the majority of Java developers easier.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The best way to provide a String merge/join facility would be to implement a new String constructor with two parameters: a String array and a delimiter.

      public String(String[] tokens, String delimiter)
      {
      // The implementation is left as an exercise to the reader ;-)
      }
      ACTUAL -
      The following pseudo code shows how the new constructor should work :

      String[] tokens = new String[]{"Hello", "World!"};

      String greeting = new String(tokens, ", ");

      System.out.println(greeting);

      The output of the code snippet should be: Hello, World!

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround would be to implement a helper mewthod that does the merge.
      (Incident Review ID: 240506)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              jgish Jim Gish (Inactive)
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: