Collections.sort(strings,new Comparator(){ public int compare(Object a, Object b) { String id1 = ((TranslatedString)a).getSource(); String id2 = ((TranslatedString)b).getResult(); return (id2.length() - id1.length()); } });   for (Iterator ite = strings.iterator(); ite.hasNext(); ){ TranslatedString ts = (TranslatedString) ite.next(); testo = Utils.replace(testo, "\""+ts.getSource()+"\"" , "\""+ts.getResult()+"\""); }
     public void InsertTranslate(File file, File fileout){        String testo = getText();        try{                BufferedReader br = new BufferedReader(new FileReader(file));                boolean chiave = false;                String key = null;                String obj = null;                String riga;                while ((riga = br.readLine())!=null){                    if (riga.startsWith("*****")){                        chiave=true;                        if (obj!=null){                            // serve come entry nel caso della prima key                            // inserisco la chiave al passo precedente                            if (key.startsWith("\n")) {                                key = key.substring(1);                            }                            if (obj.startsWith("\n")) {                                obj = obj.substring(1);                            }                            testo = Utils.replace(testo, key , obj);                            key="";                            obj="";                        }                    }                    else if (riga.startsWith("=====")){                        chiave=false;                    }                    else if (chiave==true){                        // sto leggendo una chiave                        if (key!=null){                            key = key +"\n" +riga;                        }                        else {                            key = riga;                        }                    }                    else if (chiave==false){                        // sto leggendo una chiave                        if (obj!=null){                            obj = obj +"\n" + riga;                        }                        else {                            obj = riga;                        }                    }                }                br.close();            } catch(IOException e){                System.out.println(e.getMessage());                System.err.println(e.getMessage());            }        // saving the output file        PrintStream ps;        try{            FileOutputStream fos = new FileOutputStream(fileout);            ps = new PrintStream( fos );            ps.println (testo);            ps.close();            JOptionPane.showMessageDialog(null,"OK","Message", JOptionPane.INFORMATION_MESSAGE);        } catch(IOException e ){            System.out.println(e.getMessage());            System.err.println(e.getMessage());        }    }