首页 > 解决方案 > 通过迭代二维数组返回一个对象

问题描述

在 Java 中,我创建了一个初始化的 2D 数组,表示一个有 15 排和每排 10 个座位的剧院:

Place[][] room = new Plaats[15][10];

现在我想遍历数组并返回对象 Plaats 以在其上调用方法。

private Place getPlaatObject(int rownumber, int seatnumber) {
    Place places;   
    for (int row = 1; row < room.length; row++) { // loop by the rows
        for (int seat = 1; seat < room[row].length; seat++) { // loop by the seats
            return places;
        }
    }
}

我如何返回对象?

标签: java

解决方案


推荐阅读