Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Using String.toCharArray()
Use String.toCharArray() to convert a String into a char array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// {
public class Main {
public static void main(String[] args) {
// }
String techioStr = "TechIO Playground";
char[] techioCharArray = techioStr.toCharArray();
for (char techioChar : techioCharArray) {
System.out.println(techioChar);
}
//{
}
}
//}
Press desired key combination and then press ENTER.
Convert String to Char Array Using Java 8 Stream
Use .chars() to get the IntStream, and convert it to Stream Char using .mapToObj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// {
public class Main {
public static void main(String[] args) {
// }
String techioStr = "TechIO Playground";
techioStr.chars() //IntStream
.mapToObj(x -> (char) x)//Stream<Character>
.forEach(System.out::println);
//{
}
}
//}
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content