Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to get the length of a String Array? Posted by coins on 18 Apr 2007 at 12:14 AM
I want use a loop to output the content of a String Array like
String[] NameList;
...
for(i=0;i<n;i++)
{
   System.out.println(NameList[i]);
}     

but my problem is I don't know how many elements are there
in this array, I don't know how to get the value n.
Any thought will be appreciated.
Report
Re: How to get the length of a String Array? Posted by zibadian on 18 Apr 2007 at 12:21 AM
: I want use a loop to output the content of a String Array like
:
: String[] NameList;
: ...
: for(i=0;i<n;i++)
: {
:    System.out.println(NameList[i]);
: }     
: 

: but my problem is I don't know how many elements are there
: in this array, I don't know how to get the value n.
: Any thought will be appreciated.
:
See: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#length()
Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);

Report
Re: How to get the length of a String Array? Posted by zibadian on 18 Apr 2007 at 12:22 AM
: I want use a loop to output the content of a String Array like
:
: String[] NameList;
: ...
: for(i=0;i<n;i++)
: {
:    System.out.println(NameList[i]);
: }     
: 

: but my problem is I don't know how many elements are there
: in this array, I don't know how to get the value n.
: Any thought will be appreciated.
:
Arrays have a "property" called length. Here's how to use it:
  for(i=0;i<NameList.length;i++)

Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.