String to character

how to convert a string to character?
[44 byte] By [ebtech] at [2007-9-30 20:27:22]
# 1
if you want a char[] you can use toCharArray() or getChars(...). But don't tell me that you didn't find that in the javadoc
ekupcik at 2007-7-7 1:11:47 > top of Java-index,Java Essentials,Java Programming...
# 2

String str = "t";

char ch = str.charAt[0];

or

String str = "test";

char[] chars = str.toCharArray;

amongst many other ways....

but surely you could have found that out yourself....

phawdon at 2007-7-7 1:11:47 > top of Java-index,Java Essentials,Java Programming...
# 3

u r not understand about my question.i m trying to convert a character to ASCII.for instance,

char simple='A';

int val=(char)simple;

now i m having a problem coz i have a string which is alphanumeric n i want to convert the alphabet to int using ASCII. my code is like this:

String cardID="4Dr6g8WPa684Cvf";

for (int j=0;j<cardID.length();j++)

{

String subCard="";

subCard=cardID.substring(j,j+1);

if (subCard.equals("D"))

{//char cSubCard=String.toChar(subCard);

char val1=(char)subCard;

System.out.println("val1->"+val1);

}

}

there is error stating that "char val1=(char)subCard" incompatible data type.so what should i do?

ebtech at 2007-7-7 1:11:47 > top of Java-index,Java Essentials,Java Programming...
# 4

String cardID="4Dr6g8WPa684Cvf";

for(int i = 0;i < cardId.length();++i)

{

if(cardId.charAt(i) == 'D')

System.out.println((int)cardId.charAt(i));

}

subSequence at 2007-7-7 1:11:47 > top of Java-index,Java Essentials,Java Programming...