【发布时间】:2021-09-10 05:53:04
【问题描述】:
我有一个包含数据的数组列表:
NAME LASTNAME CREDIT_CARD COUNTRY
name1 lastname1 card1 country1
name2 lastname2 card2 country2
name3 lastname3 card3 country3
上面的arraylist是由我目前使用的这段代码创建的:
public ArrayList reader() throws IOException {
while (true) {
System.out.println("Give me the Data file here : ");
String path = "";
Scanner sc = new Scanner(System.in);
path = sc.nextLine();
path = path.toLowerCase(Locale.ROOT);
if (path.contains(".txt") && !path.isEmpty() ) {
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
String str;
String[] wordsArray;
while ((str = br.readLine()) != null) {
wordsArray = str.split("\\t");
for (String each : wordsArray) {
if (!"".equals(each)) {
words.add(each);
}
}
}
System.out.println(words);
br.close();
return words;
} else {
System.out.println("Wrong type,try again");
}
}
}
我尝试将上面的列表作为一个 hasmap,其中每一行都有一个唯一的键和用户的值,例如: 键 1 = name1,lastname1,card1,country1 键 2 = name2,lastname2,card2,country2 有什么办法吗?
【问题讨论】:
-
1.代码无法编译,因为
words未定义。 2. 不清楚预期地图的键源应该是什么。 3.不清楚map的值应该是什么:字符串列表或一些Row对象。