JDK-5015163 : (str) String merge/join that is the inverse of String.split()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.2,6,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp,windows_7
  • CPU: generic,x86
  • Submitted: 2004-03-17
  • Updated: 2017-05-16
  • Resolved: 2013-04-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b89Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
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) 
======================================================================

Comments
SQE has looked at the bug and decided no additional tests are needed.
23-08-2013

See suggestions for additional improvements in this thread: http://mail.openjdk.java.net/pipermail/lambda-dev/2012-June/005085.html
30-11-2012

EVALUATION This will only be made available in JDK8
19-06-2012

PUBLIC COMMENTS See also http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-March/001205.html
17-05-2009

EVALUATION Please refer to the forum thread on this topic for several design suggestions and two different suggested fixes. Contribution-forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=10624
21-12-2005

EVALUATION I once independently suggested adding a join facility. Given that this simple functionality gets reinvented, and that split and join are often used in tandem, and that perl, which was perhaps the inspiration for split, also has join, there is strong motivation for providing join. However, I don't think adding a constructor is a good idea. The intent is not obvious enough. I would favor a static method analogous to perl's public static String join(String delimiter, String... components) or perhaps more abstractly public static String join(CharSequence delimiter, CharSequence... components) This even succeeds in copying the vargarity of perl join. ###@###.### 2005-04-13 20:40:04 GMT
13-04-2005