File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Read the records from the ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read the records from the ArrayList" Watch "Read the records from the ArrayList" New topic

Read the records from the ArrayList

Mg Oo

Joined: Nov 28, 2004
Posts: 22
Hi Java masters,

I'm facing some difficulties with a java quizz.
Please give me some ideas.

Quiz01 :

The text file has three records like :

NO.123, HirLet Road,LL 234
1 5 0 2 7000
NO.23, Hello Road,LL 235
1 5 0 2 6000
NO.23, Mine Road,LL 235
1 5 0 2 9000

According to the above info, we know the file has John's related record and Paul's related one, and Mary's related one.7000,6000 and 9000 are their respective salaries.

For each record,create an object and add it to ArrayList.
Having created all objects, write those objects to a binary where those whose salaries are over 6000.

Again, display the name of them.


For the above,

� Do I have to implement StringTokenizer() to make apart each person ?
If so,how ? I guess each record span four lines. So I cut out four lines for each record ?

� How can I compare their salaries ?
To do so,I think I have to use StringTokenizer again.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46367
You could use StringTokenizer, althought that is now deprecated.

Why not use a java.util.Scanner to read and parse the lines and data from the files?
You did say they are simple text files, didn't you?

I have never used a Comparator, but you can probably get it to produce a compare() method which works on salaries, then you can use a method like sort() in the java.util.Arrays class or the java.util.ArrayList class.

And if you win the quiz, can I share the prize?

Mg Oo

Joined: Nov 28, 2004
Posts: 22
Thank you.

Just a quizz in a school textbook
I agree. Here's the link:
subject: Read the records from the ArrayList
It's not a secret anymore!