I have a text file in my computer which i am reading form my java program , now i want to build some criteria
here is my Notepad File :
#Students
#studentId studentkey yearLevel studentName token
358314 432731243 12 Adrian Afg56
358297 432730131 12 Armstrong YUY89
358341 432737489 12 Atkins JK671
#Teachers
#teacherId teacherkey yearLevel teacherName token
358314 432731243 12 Adrian N7ACD
358297 432730131 12 Armstrong EY2C
358341 432737489 12 Atkins F4NGH
when I read from this note pad file , i get the exact data as it is in my application , but now i want to check if the token which a user just entered on my main page e,g i have the token “JK671” , if this belongs to the token present in the students or Teachers above ?
output should be like "the token JK671 belongs to Student "..
how could i achieve this ?
thanks
You’ll achieve this by iterating on your teachers and students, and comparing their code with the given token.
If the codes are unique identifiers, and your program must search by code, then you should creta e a
Map<String, Teacher>and anMap<String, Student>, where the keys of the maps are the teacher/student codes, and use the map’s containsKey method to know if such a teacher or student code exists. This will lean to O(1) searches rather than O(n).