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 Make it so: Java DB Connections & Transactions this week in the JDBC 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: 24195

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"
I agree. Here's the link:
subject: convert String to char
It's not a secret anymore!