File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes convert String to char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert String to char" Watch "convert String to char" New topic

convert String to char

Robert Johnson
Ranch Hand

Joined: Feb 11, 2005
Posts: 32
how do you convert a string to a char

Whats in a name?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Assuming it's a one-character String, you just want

String s = "a";
char a = s.charAt(0);

[Jess in Action][AskingGoodQuestions]
Robert Johnson
Ranch Hand

Joined: Feb 11, 2005
Posts: 32
yea, that worked fine thanks.
Do you know how to initialize a char variable?


char letter = ?;
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

try a google search on "java define primitive types"
wood burning stoves
subject: convert String to char
Similar Threads
Convert "\n" to char '\n'
Convert char array into a string
convert String to char
changing a String to a char
String indexing