如何在java.util程序中传递基于类的数​​组列表的参数

时间:2018-05-10 21:00:00

标签: java class methods

任何人都可以帮我纠正/ * ... * /代码,即函数static void display,以便将传递的arraylist作为参数并在那里相应地显示,我每次都会收到错误。请帮帮我,我是使用util class

的java程序的新手
import java.util.ArrayList;

public class test1{

    static void display(ArrayList<Row> arrayList1) 
    {
        ArrayList<Row> arrayList1 = new ArrayList<>();
        Row row;
     row = new Row(111,711,1110,111);
    //    rows.add(row);
     arrayList1.add(row);
    System.out.println(arrayList1); // passing the arraylist values and adding the element

 // Show the Array

        System.out.println("u\t v\t t\t lamda");
        System.out.println("------------------------------");
        for (Row printRow : rows)
        {
            System.out.println(
                    printRow.getu() + "\t " +
                    printRow.getv() + "\t" +
                    printRow.gett() + "\t" +
                    printRow.getlamda());

        }

    */

    }



    public static void main(String[] args)
    {
        ArrayList<Row> rows = new ArrayList<>();
        Row row;

        row = new Row(4,7,5,1);
        rows.add(row);
        row = new Row(3,6,6,1);
        rows.add(row);      
        row = new Row(5,9,6,1);
        rows.add(row);
        row = new Row(6,7,7,1);
        rows.add(row);
        row = new Row(6,9,7,1);
        rows.add(row);

        row = new Row(7,10,8,1);
        rows.add(row);
        row = new Row(7,10,9,1);
        rows.add(row);
        row = new Row(1,7,10,1);
        rows.add(row);


        // Show the Array

        System.out.println("u\t v\t t\t lamda");
        System.out.println("------------------------------");
        for (Row printRow : rows)
        {
            System.out.println(
                    printRow.getu() + "\t " +
                    printRow.getv() + "\t" +
                    printRow.gett() + "\t" +
                    printRow.getlamda());

        }
         display(rows);

    }/* 


}
class Row
{


    private final int u;
    private final int v;
    private final int t;
    private final int lamda;


    public Row(int u, int v, int t, int lamda)
    {
        this.u = u;
        this.v = v;
        this.t = t;
        this.lamda = lamda;
    }

    public int getu()
    {
        return u;
    }

    public int getv()
    {
        return v;
    }

    public int gett()
    {
        return t;
    }

    public int getlamda()
    {
        return lamda;
    }


}

1 个答案:

答案 0 :(得分:0)

您的list-style-type: none; margin-left: 0px; padding-left: 0em; text-indext: -1em; display: table; } .post-body ul li{ display: table-row; } .post-body ul li::before{ content:"\261e"; color: #8d8d8d; text-align: right; padding-right: .6em; display: table-cell; } .post-body ul li + li{ -moz-box-shadow: 0 -1px 0 #8d8d8d; -webkit-box-shadow: 0 -1px 0 #8d8d8d; box-shadow: 0 -1px 0 #8d8d8d; } 作为参数传递,因此如评论中所述,您不应重新声明或重新初始化它。您还可以循环浏览未定义的arrayList1,而不是循环遍历rows

arrayList1