如何从ArrayList获取secound行

时间:2015-05-31 14:58:04

标签: java arraylist

    package Nauka;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Random;

    public class NaukaGamy {
    public static void main(String[] args) {
        ArrayList<Akord> gamy = new ArrayList<Akord>();

        gamy.add(new Akord("C dur\n\n","  c', d, e, f, g, a, h, c"));
        gamy.add(new Akord("C moll\n\n","  c, d, es, f, g, as, b"));

        System.out.println(gamy.get(1));

结果是:Nauka.Akord@7852e922

我要将secound line(C moll \ n \ n&#34;,&#34; c,d,es,f,g,as,b)作为解决方案。怎么做?

1 个答案:

答案 0 :(得分:0)

您需要在班级toString()中覆盖Akord方法。例如,

public class Akord {
    @Override
    public String toString() {
        return /*your fields to String*/;
    }
}