Details
-
Enhancement
-
Resolution: Fixed
-
P3
-
1.4.2, 6, 7
-
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)
======================================================================
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
- duplicates
-
JDK-8004246 Miscellaneous improvements to StringJoiner
- Closed
-
JDK-7172407 There should be better printing functionality of List, Sets and Maps
- Closed
- relates to
-
JDK-7175206 (str) StringJoiner subsequence on suffix always returns whole suffix instead of requested part
- Resolved
-
JDK-7172553 A utility class that forms the basis of a String.join() operation
- Closed
-
JDK-6538167 (coll) Please add Collections.toString(Collection collection, String separator)
- Closed