Code example for HashSet

Methods: addAll

0
import java.util.Arrays; 
import java.util.HashSet; 
 
public class FilenameExtFilter implements FilenameFilter {
 
    private HashSet<String> mExts = new HashSet<String>();
 
    public FilenameExtFilter(String[] exts) {
        if (exts != null) {
            mExts.addAll(Arrays.asList(exts));
        } 
    } 
 
    public boolean contains(String ext) {
        return mExts.contains(ext.toLowerCase());
    } 
 
    public boolean accept(File dir, String filename) {
 
        File file = new File(dir + File.separator + filename);//(目录/文件名)  格式
        if (file.isDirectory()) {//如果dir + File.separator + filename是一个目录的话