Language/Java
[Java] String to List
_Hiiro
2022. 11. 7. 00:58
String to List<Character> 변환
//String -> List<Character>
String str = "abc"
List<Character> list = str.chars().mapToObj(c -> (char) c).collect(Collectors.toList());
String to List<Integer>변환
//String -> List<Integer>
String str1 = "123";
int[] intArr = Arrays.stream(str1.split("")).mapToInt(Integer::parseInt).toArray();
List<Integer> list2 = Arrays.stream(intArr).boxed().collect(Collectors.toList());