How to convert/parse from String to char in java?

Yokhen picture Yokhen · Oct 21, 2011 · Viewed 937.3k times · Source

How do I parse a String value to a char type, in Java?

I know how to do it to int and double (for example Integer.parseInt("123")). Is there a class for Strings and Chars?

Answer

Mark Byers picture Mark Byers · Oct 21, 2011

If your string contains exactly one character the simplest way to convert it to a character is probably to call the charAt method:

char c = s.charAt(0);