File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Arrays and strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays and strings" Watch "Arrays and strings" New topic
Author

Arrays and strings

jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
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

Joined: Mar 26, 2002
Posts: 442
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

Joined: Dec 10, 2001
Posts: 7023
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?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Arrays and strings