Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lenght of string array 1

Status
Not open for further replies.

raioveil

Technical User
Sep 4, 2000
3
PT
Hello. I'm new to Java (as you can notice ...) and I'm starting with some simple programs. I've tested a program I got from a book and I'm getting a compile error I don't quite understand (don't understand what's wrong ...). I'm using SUN jdk1.2.2 Can anyone please help ?

Thanks

<this is the java code>
import java.io.*;
import java.util.*;

public class DirList {

public static void main (String[] args) {

File path = new File(&quot;.&quot;);
String[] list;

list = path.list();

for (int i = 0; i < list.lenght; i++)
System.out.println(list);

}
}

<this is the compiler error>

DirList.java:18: Attempt to reference field lenght in a java.lang.String[].
for (int i = 0; i < list.lenght; i++)
^
1 error
 
Not lenght :))).
for (int i = 0; i < list.length; i++)

Otto.
 
And I think you wanted to write
System.out.println(list);

Bye, Otto.
 
I think that you wanted to put length(). As length is a method that returns a integer not a variable in the the class String. my second post:)

Chris
 
Sorry, but I was wrong in my second post. I wanted to write (and maybe raioveil too) list.
System.out.println(list);

Chris,
I do not understand you. You are right in that the String class has a length() method. But in the question String array was use (String[]), and the arrays have only length property, not length() method.

Bye, Otto.
 
Many thanks to you all. Basic typing mistake (I'm ashamed ...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top