This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 24189

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"
Have you checked out Aspose?
subject: convert String to char
It's not a secret anymore!