【发布时间】:2020-10-23 19:28:48
【问题描述】:
我目前正在阅读 java 的有关文件的 IO 章节,让我想知道如果, 文本文件中有不同的数据类型,例如:
Position(in type String), ID(in type long), Name(in type String), Birthdate(dd/mm/yy in 3 type ints), title(Ms/Mr/Dr in type String), tasks done(in type int):
file name: employeeInfo.txt
Manager, 987298347, Tesla, 03,04,1969, Mr, 4
Assistant, 290375020, Chris, 17,11,1989, Mr, 5
Manager, 99832482322, Steph, 11,02,1980, Ms, 4
Assistant, 679730283, Pete, 09,10,1980, Mr,7
如何在代码中将它们存储到两个根据位置分组的 ArrayList 中?为了让我做任何灵活的任务,例如:
1. able to find out which employee achieve task done with more than 3
2. display employee's info when its ID is entered
Then the result may be as follows if 2 is invoked:
input:
290375020
output:
Assistant, 290375020, Chris, 17/11/1989, Mr, 5
我希望不会造成任何混乱。 提前谢谢你
【问题讨论】:
-
读取文件并拆分每一行,然后将每个元素转换为相应的数据类型,而不是 arraylist,您可以使用 hashmap