파일 처리 프로그램이 있습니다.문자열을 큰 arrayList와 비교하는 가장 빠른 방법
파일 이름 (문자열)을 파일 이름의 ArrayList
에 대조하는 방법이 있습니다. 아이디어는 프로그램이 이미 ArrayList
에있는 파일을 처리 할 필요가 없다는 것입니다.
내가 가지고있는 문제는 ArrayList
이 매우 커서 (16,000 개의 요소가 될 수 있음) 모든 파일을 동일한 번호로 반복하여 각 파일을 ArrayList
에 대해 검사하는 데 너무 많은 시간이 걸린다는 것입니다. 나는 .contains
을 사용하고 있기 때문에 이것이라고 생각합니다.
이 문자열을 매우 큰 arrayLists와 비교할 때 ArrayList
비교를 수행하는 더 효율적인 (즉 빠른) 방법이 있습니까? 아니면 다른 데이터 구조에 저장해야합니까?
내 코드 : 모든
public class Iterator {
static ArrayList<String> myFiles = new ArrayList<String>();
static String filename= "/Files/FilesLogged.txt";
public static void main(String[] args) throws IOException, SAXException, TikaException, SQLException, ParseException, URISyntaxException, BackingStoreException {
BufferedReader reader = new BufferedReader(new InputStreamReader(ClassLoader.class.getResourceAsStream(filename)),2048);
String line = null;
while((line = reader.readLine()) != null) {
myFiles.add(line);
}
reader.close();
}
public static void loopthrough(String folderName) throws IOException, SAXException, TikaException, SQLException, ParseException, URISyntaxException{
System.out.println("This is the loopthrough folderName"+folderName);
File dir = new File(folderName);
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
if(!myFiles.contains(child.getName())){
System.out.println("THE FILE NAMES ARE"+child.getName().toString());
}
}
}
코드를 올바르게 포맷하십시오. 지금은 읽을 수 없습니다. –
대신 HashSet을 사용하지 않는 이유는 무엇입니까? –
해시셋이 빠릅니까? –