i have a text file i want to add its data to priority queue and then print out 5 items with max value each line first has a name then a date then a value i want to print 5 max values with name and date
Queue<String> queue = new PriorityQueue<String>();
String file = "file";
String line;
int order = 1;
try{
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while ((line = br.readLine()) != null) {
queue.offer(line);
}
br.close();
} catch (IOException e){
System.out.println("File not found");
}
while (!queue.isEmpty()){
System.out.println(order + ".Number: " + queue.poll());
order++;
}
data.txt :
tloxJcdiMqMWyDW 1976-11-24 3747
KWuHczAFXRGCeTZ 2015-12-5 1740
SyAckDyYyZhrsEK 1920-8-3 3164
pjKEnTTfcdoJwMy 2016-12-28 1941
ZsvJcYbmOFmdXfG 1923-10-10 8314
qkqDyFhObQVpByH 1934-7-21 4907
IRUMpmTSmJDVIJU 2012-12-26 376
nOCCDAmTilqnukW 1968-5-3 5811
uecbYlaCeaTSAsr 1937-4-1 9305
AMdPXptNGayPPAM 1949-2-25 1130
afTQNxogdxpQRpF 1912-11-18 5637
hBUJpjBJgyShNqk 2011-12-9 4075
dMGDWfIrPctuwBs 2005-3-15 8567
UBELfqonZOmmEGf 1954-7-29 7875
EuMbAKoKwYYERxy 1902-3-4 8291
OXvvwLXJjsXrfVI 1927-4-29 4693
amHPTQXCqHkYtXW 1991-8-24 8778
gfAcsQpChfukGlK 1971-7-14 4204
WHguJUYeLBYoton 1987-11-24 9664
ZvMoXwJqLhBlWiG 2006-6-7 7893
i have tried some other ways to save data to PQ and still didnt get any result