Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read String characters

Status
Not open for further replies.

MaxGeek

Technical User
Jan 8, 2004
52
US
Hi,
I'm trying to figure out how to read the first character of a String. Like if the user inputs, Yes, YES, y, or No, N.

I'm not sure if its the correct thing to use right now but I'm trying to use "startsWith."
 
Code:
//It is a corrent choice to use startsWith.
//Be careful in using empty string
String hello = "yes";
if (hello.startsWith("yes"))
   System.out.println("Morning");

if (hello.startsWith(""))
   System.out.println("Good Evening");
// you can use charAt for one character but more coding is needed
 
Could you give me an example of using charAt? I understand that it may be more code, but wouldn't it cover more varieties of input like just Y. Would their be issues with upper case and lower case?
 
Thanks for the example and for the link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top