wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes get string length 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 » Beginning Java
Bookmark "get string length" Watch "get string length" New topic
Author

get string length

Melinda Wilson
Ranch Hand

Joined: Jul 05, 2001
Posts: 35
Beginner java programmer.
I need to get the string length of a string array:
This generated an error:
int astrArrayLength = astrArray.length(); //get string length
for (int i = 0; i < astrArrayLength; i++)

This got rid of the error:
int astrArrayLength = astrArray.length; //get string length
for (int i = 0; i < astrArrayLength; i++)
Is length relaced with length()?
Thank you.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Is length relaced with length()?
No, I doubt that the compiler does anything special behind the scenes. Just think of any array in Java as an Object that has a length attribute. It's just one of those little quirks that you have to remember: arrays have a length attribute while String has a length() method. Go figure.

Junilu - [How to Ask Questions] [How to Answer Questions]
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
array.length will return the length of an array.
string.length() is a method that returns the length of a string.
Every array inherently knows its own length. It's a property of an array and can be shown with the array.length . I know it's a bit confusing, but just remember that's how it is.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get string length
 
Similar Threads
Array Sizes
StringBuffer's setCharAt - near help
Null Pointer Exception
Null Pointer Exception
get the length of the string