• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array of Strings  RSS feed

 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to ask a question about array of strings.
Given an array of strings names[] (size unknown.)

Is there a simple way to know:
#1> Total number of strings in the array.
#2> Length of each string.


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get the length of an array by looking at the length property:

You get the number of characters in a String by calling the length() method.
 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
I was confused between length property and length method.Your answer helped me.
I just wrote a sample program and now understand it well.

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks correct.

Arrays have a length property, and class String has a length() method to get the length of the string.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!