public class ConvertStringToCharArrayExample{
public static void main(String []args)
{
String myString = "Hello World!";
System.out.println(myString);
Field value;
try {
value = String.class.getDeclaredField("value");
value.setAccessible(true);
char[] values = (char[])value.get(myString);
for(char val:values)
{
System.out.println(val);
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment