• Post Reply Bookmark Topic Watch Topic
  • New Topic

First element in string  RSS feed

 
nida lulu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I only want the first element in my string, for example my string is "the man on the moon" and I want to store "t" as a char is that possible?
The reason I am saying this is because I want to use getNumericValue(char ch) from the Character class on the first element, in this case 't'.
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Nida,

Welcome to JavaRanch.
I think toCharArray() method of String class may help you.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Saurabh Pillai:

I think toCharArray() method of String class may help you.


Not as much as "charAt(int)" would!
 
nida lulu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked up charAt() in the API and it worked just fine! thanks!
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Not as much as "charAt(int)" would!
Yeah! Thanks EFH.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!