I have a string and I need to cross it as a char array. Of course, the normal method is to use toCharArray()
String str = "Hello"; char[] charArr = str.toCharArray();
Now the source code for toCharArray () is as follows.
public char[] toCharArray() {
So, Java creates a new object in memory of type char [] and copies the string object to the new object.
My question is whether it is possible to use a string as char [] without copying the array. My intention is to save on memory. If this is not possible, is there a reason?
Thanks in advance!
java string char java-8
Jordan epstein
source share