notme
1 year ago
1 changed files with 24 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||||||
|
package org.chulk.sanxbox; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
public class TestSnippets { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testStringConcat() { |
||||||
|
String[] strings = { "apple", "banana", "cherry", "date" }; |
||||||
|
String delimiter = ","; |
||||||
|
String firstDelimiter = ":"; |
||||||
|
|
||||||
|
String joinedString = Arrays.stream(strings) |
||||||
|
.findFirst() |
||||||
|
.map(s -> s + firstDelimiter + Arrays.stream(strings).skip(1).collect(Collectors.joining(delimiter))) |
||||||
|
.orElse(""); |
||||||
|
|
||||||
|
System.out.println(joinedString); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue