I started coding recently and I got stuck for several days already. So I need to get "value" from "key", which is in table like:
one uno
two dos
three tres
four cuatro
N.B.: words are separated by tab, therefore using "/t"
and what newbie me could accomplish looks something like this:
import java.util.*;
import java.io.*;
public class test {
public static void main(String[] args)throws FileNotFoundException, IOException {
Scanner scanner = new Scanner(new FileReader("C:\\Users\\Admin\\workspace\\test_dict\\src\\source.txt"));
HashMap<String,String> map = new HashMap<String,String>();
while (scanner.hasNextLine()) {
String[] columns = scanner.nextLine().split("\t");
map.put(columns[0],(columns[1]));
//enter a key word
System.out.println("Enter a word");
String[] columns = scanner.nextLine();
//ignoring upper and lower case
columns=columns.toLowerCase();
// returns the element associated with the key
System.out.println(map.get(columns[]));
//close files
scanner.close();
}
}
}
The problem is: I want to be able to type in the console the key word and get associated value to it. eg:
Enter a word:
one
uno
But I can't use map.get(columns[]);
and when I try map.get(columns[0]);
for some weird reason it shows me columns[1]
so in console i got
Enter a word:
uno
Enter a word:
dos
Enter a word:
tres
Enter a word:
cuatro