해시 테이블을 구현했는데 내용을 표시하고 싶지만 어떻게 해야할지 잘 모릅니다.자바에서 내 해시 테이블의 내용을 표시하는 방법
package myHashTable;
import java.util.InputMismatchException;
import java.util.Scanner;
public class MyHashDrivergood{
private static String fileName = "";
private static int choice = 0;
private int initialCapacity = 0;
private static String[] testData = null;
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
MyHashTableTable<String, String> dataTested = new MyHashTableTable<String,String>
()>;
while(choice != 999){
try {
System.out.println("Please enter your choice to use the HashTable: (999:
End of program) ");
System.out.println("Read the files, store data in an array, and display
the content: 1 ");
System.out.println("Read the files and store the data in the HashTable, and
dislay the content of the hashtable: 2");
choice = keyboard.nextInt();
keyboard.nextLine();
} catch (InputMismatchException e) {
System.out.println("Please enter only numbers!");
keyboard.nextLine();
continue;
}
switch(choice){
case 1:
System.out.print("Please enter the file name to test:");
fileName = keyboard.next();
testData = new String[MyHashTablegood.getFileSize(fileName)];
testData = MyHashTablegood.getData(fileName,
MyHashTablegood.getFileSize(fileName));
for(int j = 0;j < testData.length; j++){
System.out.println(j + " " + testData[j]);
}
break;
case 2:
System.out.print("Please enter the file name to test:");
fileName = keyboard.next();
//here I read the data from a file
testData = new String[MyHashTablegood.getFileSize(fileName)];
testData = MyHashTablegood.getData(fileName,
MyHashTablegood.getFileSize(fileName));
//now I am storing the data in my hash table
for(int k =0; k < testData.length; k++){
String data = testData[k];
dataTested.put(data, data);
}
break;
}
}
keyboard.close();
System.out.println("The program has ended.");
}
}
그것은 내가 해시 테이블에서 작동 처음 내가 내가 뭐하는 거지의 확실하지 않다 :
여기 내 드라이버 클래스입니다.
을 인쇄하는 것입니다. – Melquiades