import java.io.*; import java.util.*; public class InimSort{ public static void main(String[] arg) throws IOException{ LinkedList inimesed=new LinkedList(); BufferedReader failist=new BufferedReader(new FileReader("inimesed.txt")); String rida=failist.readLine(); while(rida!=null){ StringTokenizer tykeldaja=new StringTokenizer(rida); String en=tykeldaja.nextToken(); int sa=Integer.parseInt(tykeldaja.nextToken()); Inimene in=new Inimene(en, sa); inimesed.add(in); rida=failist.readLine(); } failist.close(); InimVordleja vordleja1=new InimVordleja("eesnimi"); Collections.sort(inimesed, vordleja1); System.out.println(inimesed); Iterator it=inimesed.iterator(); FileOutputStream fos=new FileOutputStream("inimandmed.dat"); ObjectOutputStream inimvaljund=new ObjectOutputStream(fos); while(it.hasNext()){ Inimene abi=(Inimene)it.next(); //System.out.println(abi.eesnimi+" "+abi.synniaasta); inimvaljund.writeObject(abi); } //Lugege faili kirjutatud inimesed ekraanile inimvaljund.close(); } }