The easy way to do this is:
For whole String into ASCII :
public class ConvertToAscii{
public static void main(String args[]){
String abc = "admin";
int []arr = new int[abc.length()];
System.out.println("THe asscii value of each character is: ");
for(int i=0;i<arr.length;i++){
arr[i] = abc.charAt(i); // assign the integer value of character i.e ascii
System.out.print(" "+arr[i]);
}
}
}
THe asscii value of each character is:
97 100 109 105 110
abc.charAt(i)
gives the single character of String array:
When we assign each character to integer type then, the compiler do type conversion as,
arr[i] = (int) character // Here, every individual character is coverted in ascii value
But, for single character:
String name = admin;
asciiValue = (int) name.charAt(0);// for character 'a'
System.out.println(asciiValue);