String class function
getBytes() Method
String getBytes() method is used to get byte array of the specified
string.
public class Demo {
public static void main(String[] args) {
String a="studytonight";
byte[] b=a.getBytes();
for(int i=0;i<b.length;i++)
{
System.out.println(b[i]);
}
}
}
, getChars() Method
String getChars() method is used to copy the content of the string into a char
array.
public class Demo {
public static void main(String[] args) {
String a= new String("Hello Welcome to studytonight.com");
char[] ch = new char[16];
try
{
getBytes() Method
String getBytes() method is used to get byte array of the specified
string.
public class Demo {
public static void main(String[] args) {
String a="studytonight";
byte[] b=a.getBytes();
for(int i=0;i<b.length;i++)
{
System.out.println(b[i]);
}
}
}
, getChars() Method
String getChars() method is used to copy the content of the string into a char
array.
public class Demo {
public static void main(String[] args) {
String a= new String("Hello Welcome to studytonight.com");
char[] ch = new char[16];
try
{