Use a Map<String, String>
. And use Files.readAllLines()
:
final Map<String, String> entries = new HashMap<>();
final Path dict = Paths.get("dictionaryTXT.txt");
String[] array;
for (final String line: Files.readAllLines(dict, StandardCharsets.UTF_8)) {
array = lines.split("\\s*:\\s*");
entrues.put(array[0], array[1]);
}
Then to search for a word:
final String description = entries.get(input);
if (description == null)
System.out.println("not found");
else
System.out.println("definition: " + description);
Of course, if your dictionary is extra large, you'll want to use Files.newBufferedReader()
instead and read line by line.
Also, the code above lacks basic error checking; exercise left to the reader