my dog learned polymorphism
The moose likes Beginning Java and the fly likes Find the last character in a srting. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Find the last character in a srting." Watch "Find the last character in a srting." New topic

Find the last character in a srting.

Alec Porter

Joined: Sep 05, 2010
Posts: 29
I' trying to find out how do you know how many characters are in a string. Because to use getChars you have to know before hand how many characters you want to end at.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63532

Have you checked the javadoc for the String class? (and please proof-read your posts -- "srting"?)

[Asking smart questions] [About Bear] [Books by Bear]
Mina Daoud
Ranch Hand

Joined: Sep 24, 2010
Posts: 88
The Java API docs will answer your question. You can find it in this link
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45266
I am sure there is an easier way to do it than use getChars.
Java Reni

Joined: Oct 01, 2010
Posts: 1
you can try:

Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Java Reni wrote:you can try:

How would you find the last character in a String with lastIndexOf(..) ??

Regards, Rene Larsen
Dropbox Invite
Devaka Cooray
ExamLab Creator

Joined: Jul 29, 2008
Posts: 3782

"Java Reni", please check your private messages regarding an important administrative matter.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
So you want to find the *cough* length *cough* of a String huh..... I wonder if the API has information about how to find the *cough* length *cough*

Welcome to Java Ranch!

Everyday in every way, we get a little better.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20180

Don't forget a method to get the char at a specific position. However, what you should never forget are two cases: a) the string is empty (i.e. there is no last character), and b) the string reference is null (i.e. there is no string at all).

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Find the last character in a srting.
It's not a secret anymore!