Some commonly used type conversion

 

 int [] transfer list

Arrays.stream(int[]).boxed().collect(Collectors.toList());

eg:

int[] Numbers = formationService.getElementNumbers(userInSession);
List<Integer> elementList = Arrays.stream(Numbers).boxed().collect(Collectors.toList());
String into a char []
char[] chars1 = str.toCharArray();
char [] String to convert
String str1 = new new String ( chars); // constructor by String String str2 = . String valueOf ( chars); // String by type conversion, but also the actual new String (char [])   

Array and List

List < of ClassA > List1 = Arrays. AsList ( chars); // Arrays of tools by List < of ClassA > List2 = new new the ArrayList <> ();   // tools by Collections Collections. The addAll ( List2, chars);


List converted to an array of packaging types
List<ClassA> list = new ArrayList<>();
list.add('1');
list.add('2');
ClassA[] chars =  list.toArray(new Character[list.size()]);//注意toArray()的参数
String turn List

String str1 = "123456"; // embodiment a List < String > List1   = Arrays,. AsList ( STR. Split ( "")); //str.split () Returns a String [] array @ embodiment two List < String > List2 = new new the ArrayList <> (); . the Collections the addAll ( List2, . STR Split ( ""))




List String turn
public static void listToString(){
List<String> list = Arrays.asList("1","2","3","4");
String str = String.join("", list); //"1234"
}
//String.join 可以添加符号
List and Set Huzhuan
 List < String > list = new new the ArrayList <> (); the Set < String > SET = new new HashSet <> ( list);   // constructor can directly Similarly, set list also transfer this rotation when the rotation String set, first is divided into an array of sub-List, and then becomes set. when the set switch String, use String. the Join ()



 

Guess you like

Origin www.cnblogs.com/easilyai/p/10980286.html