1

I have been trying to display a folder list in Java using this code :

class Folder { boolean isFile; String folderName; List<Folder> subFolders = new ArrayList<Folder>; } class ListF { public static void main(String args[]) { File fname = new File("C:/hello"); Folder obj = new Folder(); if (fname.isDirectory()) { File[] fileNames; fileNames = fname.listFiles(); for (i = 0; i < fileNames.length; i++) { obj.subFolders.add(fileNames[i]); } System.out.println("The list is " + obj.subFolders); } } } 

But I am getting an error in my code:

ListF.java:5: '(' or '[' expected List<Folder> subFolders=new ArrayList<Folder>; 

Can anyone point out my error? Thanks.

2 Answers 2

3

Replace new ArrayList<Folder>; by new ArrayList<Folder>();

Sign up to request clarification or add additional context in comments.

Comments

1

List<Folder> subFolders = new ArrayList<Folder>;

Make the above statement as :

List<Folder> subFolders = new ArrayList<Folder>(); 

Or

If you are using Java 7 and above, you can do this too....

List<Folder> subFolders = new ArrayList<>(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.