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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extends ArrayList 1

Status
Not open for further replies.

vasah20

Programmer
Feb 16, 2001
559
0
0
US
Hi.

I want to override one of the constructors in ArrayList, namely the

Code:
public ArrayList(Collection c) {

}

constructor, but I want to perform some operations on the Collection before calling super. Is there anyway that I can do this?

What I'm trying to accomplish is an ArrayList of files that only have the "html" extension. Ideally I'd like to pass in an array of files and directories, and my HTMLArrayList will filter out everything that doesn't end with "html".

thoughts?

 
>> Is there anyway that I can do this?

No, super() must be called as the first line in the constructor.

-pete
 
Pete,

Can't he just call super's empty constructor, then perform the validation, calling add() when necessary?
 
Sure, there are other things he could do as well, but that's not what he asked

>> but I want to perform some operations on the Collection before calling super

-pete
 
IF you get your initial array of directories and files from a directory via the File class, then you could use the "listFiles(FileFilter filter)" method of the "File" class (You must implement a Filefilter for this) instead of "listFiles()", so that you get only the files you want right away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top