我读文字。我的文字是这样的

AYSE;SERDAR-9.8;EMRE-5.2;AYTAC-3.3
FATMA;OYTUN-8.8;ORKUN-7.5;ONUR-5.4;UMUT-4.4;BERK-3.3;CAN-3.2
DERYA;VELI-7.7;ALI-6.5;SUAT-6.0;YAVUZ-5.0;OYTUN-4.2;ORKUN-3.1
DILARA;DOGUS-8.8;VELI-7.4;ALI-6.5;SUAT-5.5;YAVUZ-3.1
BEGUM;SUAT-6.6;YAVUZ-5.1;OYTUN-4.3;ORKUN-4.0
BERIL;CANER-8.7;DOGUS-7.5;VELI-6.2;ALI-6.1;SUAT-5.8;YAVUZ-4.8;OYTUN-4.0
FUNDA;ORKUN-9.7;ONUR-8.3;UMUT-7.2;BERK-6.5;CAN-5.5
ISIL;AYTAC-8.3;CANER-7.4;DOGUS-6.5;VELI-5.5;ALI-5.4;SUAT-4.4;YAVUZ-4.0;OYTUN-3.9;ORKUN-3.5;ONUR-3.4;UMUT-3.2;BERK-3.1;CAN-3.0
ELIF;EMRE-7.4;AYTAC-6.1


ı无法将“ u.eleman”和“ u.uyum”值添加到“ treeset tSU”。当系统无法在tSU TREESET中看到它们时,它将提供内存地址。我想将所有这些添加到树集。我该怎么办..请帮助

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet;

public class Rapor {

    static class Uyum implements Comparable<Uyum> {
        String eleman;
        Double uyum;

        public int compareTo(Uyum u) {
            if (uyum < u.uyum)
                return -1;
            if (uyum > u.uyum)
                return 1;
            return 0;
    }
    }
    public static void main(String[] args) {
            FileInputStream fIS;

            try {
                fIS = new FileInputStream("C:\\deneme\\rapor.txt");
                Reader r;
                r = new InputStreamReader(fIS, "UTF-8");
                BufferedReader bR = new BufferedReader(r);

                String satır;
                String[] point, p2;
                while ((satır = bR.readLine()) != null) {
                    point = satır.split(";");
                    String kelime = point[0];
                    HashMap<String, TreeSet<Uyum>> uyumlar = new HashMap<String, TreeSet<Uyum>>();
                    TreeSet<Uyum> tSU = new TreeSet<Uyum>() ;
                    Uyum u ;

                    for (int i = 1; i < point.length; i++) {
                         p2=point[i].split("\\-");
                         u = new Uyum();
                        u.eleman = p2[0];//EMRE,AYTAC,..
                        u.uyum = Double.parseDouble(p2

[1]);//7.8,9.5
tSU.add(u);

                    }

                    uyumlar.put(kelime, tSU);
                    System.out.println(uyumlar);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }// main end

}// class end

最佳答案

当系统无法在tSU TREESET中看到它们时,它将提供内存地址。


不,它不打印内存地址。它以十六进制打印对象的类名称,@和哈希码-默认情况下,Object.toString()会执行此操作。

如果希望以不同的方式打印Uyum对象,请在类toString()中重写Uyum方法。

09-27 17:33