File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to convert from string( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "how to convert from string("a") to char.." Watch "how to convert from string("a") to char.." New topic
Author

how to convert from string("a") to char..

Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Hi,
Does anyone explain to me how to convert from string("Y") to char?

THANKS
John Lockheart
Ranch Hand

Joined: Oct 13, 2006
Posts: 115
String y = "Y";
char y_char = y.charAt(0);

And if the string is bigger than 1 letter you can do the same thing with a loop or break up the string and send it into a character array with the following:

String y = "hello";
char[] array = y.toCharArray();

array = {'h', 'e', 'l', 'l', 'o'}
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 679

I plan to use the following method to convert String to char:



This code doesn't throw an exception, but it doesn't print the null characters either.

Is this OK?

Kaydell
 
I agree. Here's the link: jrebel
 
subject: how to convert from string("a") to char..
 
Similar Threads
Convert a char from lower case to uppercase
convert String to char
convert String to char
Convert "\n" to char '\n'
Convert char array into a string