DekGenius.com
JAVA
java string to char array
String str = "example";
char[] ch = str.toCharArray();
char array to string java
char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
String str = new String(a);
convert string to character array
public static void main(String[] args) {
String name = "chathumal";
char[] ch = name.toCharArray();
System.out.println(Arrays.toString(ch));
}
change string to char array
String myString = "Hello, world!";
char[] myCharArray = myString.toCharArray();
Convert string to char array in Java
public class Demo {
public static void main(String []args) {
String str = "Tutorial";
System.out.println("String: "+str);
char[] ch = str.toCharArray();
System.out.println("Character Array...");
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i]+" ");
}
}
}
OUTPUT:
String: Tutorial
Character Array...
T u t o r i a l
java char array to string
final char[] charArray = { 'g','e','e','k','s','f','o','r','g','e','e','k','s' };
String string = new String(charArray);
System.out.println(string);
// -> "geeksforgeeks"
convert array of char to string java
String str = String.valueOf(arr);
To Char Array
var str = "HELLO";
var charArray = str.ToCharArray();
var strNew = new string(charArray);
char array to string in java
// Method 1: Using String object
char[] ch = {'g', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g'};
String str = new String(ch);
System.out.println(str);
string to char array
const string = 'word';
// Option 1
string.split('');
// Option 2
[...string];
// Option 3
Array.from(string);
// Option 4
Object.assign([], string);
// Result:
// ['w', 'o', 'r', 'd']
String to Char array
String s="abcd";
char[] a=s.toCharArray();
for(char c:a)
{ System.out.println(c); }
© 2022 Copyright:
DekGenius.com