Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

length function for string

 
Rajesh Veluchamy
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
For static data, the below code is fine,


but in runtime if the length of data is reduced, it throws exception
i have read something like length function

may be "data.length"

Thanks to all, in advance
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String have a length method. And arrays have a length property. See the JavaDocs for more.
 
Campbell Ritchie
Sheriff
Posts: 51388
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should have given a bit more detail, Paul.

You could write "for(int i = 0; i < data.length; i++). . ." or "for(int i = 0; i < myString.length(); i++). . ."

but for an array, if you simply want to go through all the elements, use the "enhanced for" loop, (sometimes called the for-each loop), but you can't say "c = anything".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic