Change from Array to List

I have changed the file_format variable from an array to a list type. This allows any number of file formats to be passed.
This commit is contained in:
efrick 2021-08-17 14:06:00 -04:00
parent 1d9b1ede4d
commit dc53ab5e12

View File

@ -19,6 +19,8 @@ package picture_lister;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
/**
*
@ -35,14 +37,14 @@ public class Picture_Lister {
System.exit(0);
}
String picture_dir = args[0];
String[] file_format = new String[10];
if (args.length > 1){
List<String> file_format = new ArrayList<>();
if (args.length > 1){//Check if any argumets other than the path have been passed.
for(int i = 1; i < args.length; i++){
file_format[i-1] = args[i];
file_format.add(args[i]);
}
} else {
file_format[0] = ".png";
file_format[1] = ".jpg";
} else {//The default formats to look for if none are given.
file_format.add(".jpg");
file_format.add(".png");
}
System.out.println(picture_dir);
//Creating a File object for directory
@ -52,7 +54,7 @@ public class Picture_Lister {
@Override
public boolean accept(File dir, String name) {
if(name.lastIndexOf('.')>0) {
String[] include = file_format;
String[] include = file_format.toArray(new String[file_format.size()]);
// get last index for '.' char
int lastIndex = name.lastIndexOf('.');