Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays and strings

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table that is reference for an array of and String object references where some elements may be null. Code the statements needed to determine the total character length of all the String objects and display the result as a simple integer value.
Part of the problem i a having is how can you count how many arrays are selected.
public static void main(String[] args) {
String[] names = new String[];
System.out.println("Length of first
string: " + names[0].length());
}
}
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
start by checking for null first, so before printing the length do the following
[ edited to alleviate the pain of scrolling left and right -ds ]
[ March 24, 2003: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part of the problem i a having is how can you count how many arrays are selected.
I'm not sure what you mean. Could you try to describe your problem more?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic