stringutils.join....String.join()

StringUtils.join () and String.Join () Purpose: to set the array or a mosaic character spliced ​​together to form a new string.

1.StringUtils.join()方法:

Before (1) for an introduced first common-lang3 jar package,

                List <String> List = new new the ArrayList <> (); 
        List.add ( "Mxy" ); 
        List.add ( "the StringUtils" ); 
        List.add ( "the Join" ); 
        String the Join = StringUtils.join (List, " - "); // List incoming set of type String, a" - "sign splicing 
        System.out.println (the Join); 
        
        String [] S = new new String [] {" Yuan "," Mxy "}; // incoming array of type String, a "-" sign splicing 
        String join2 StringUtils.join = (S, "-" ); 
        System.out.println (join2);
---------------------  
Disclaimer: This article is CSDN blogger "YuanMxy 'original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement. 
Original link: HTTPS: // blog.csdn.net/YuanMxy/article/details/81012697
View Code

Mxy-StringUtils-join
Yuan-Mxy

 

2.String.join () method: String.join () is a new method JDK8 (no lead package

 

 

Here and StringUtils.join () are different, the order parameters are not the same, further, StringUtils.join () can be passed Integer or other type of collection or array, String.Join () can be passed to achieve the best set of interface types charSequence or arrays.

If a string type of collection or array recommended String.Join ()
---------------------
Disclaimer: This article is CSDN blogger "YuanMxy" original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/YuanMxy/article/details/81012697

Guess you like

Origin www.cnblogs.com/woainixxx/p/11360469.html