File tree Expand file tree Collapse file tree
core-java/src/test/java/org/baeldung/java/lists Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .baeldung .java .lists ;
2+
3+ import java .util .Arrays ;
4+ import java .util .List ;
5+ import java .util .stream .Collectors ;
6+
7+ import org .apache .commons .lang3 .StringUtils ;
8+ import org .junit .Test ;
9+
10+ public class ListToSTring {
11+
12+ @ Test
13+ public void whenListToString_thenPrintDefault () {
14+ List <Integer > intLIst = Arrays .asList (1 , 2 , 3 );
15+ System .out .println (intLIst );
16+ }
17+
18+ @ Test
19+ public void whenCollectorsJoining_thenPrintCustom () {
20+ List <Integer > intList = Arrays .asList (1 , 2 , 3 );
21+ System .out .println (intList .stream ()
22+ .map (n -> String .valueOf (n ))
23+ .collect (Collectors .joining ("-" , "{" , "}" )));
24+ }
25+
26+ @ Test
27+ public void whenStringUtilsJoin_thenPrintCustom () {
28+ List <Integer > intList = Arrays .asList (1 , 2 , 3 );
29+ System .out .println (StringUtils .join (intList , "|" ));
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments