aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 24168

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
Similar Threads
convert String to char
String indexing
Convert char array into a string
Convert "\n" to char '\n'
changing a String to a char