如何从多维字符串数组中提取字符串数组并在方法中返回它 - java?

时间:2015-04-19 00:18:34

标签: java arrays string multidimensional-array

在Java中,我有String [] [],我需要返回这个多维数据结构的单行(即String数组)。这是我正在使用的代码:

private static String[] getData(String routeInfo) {
    int i = 0;
    int j = 0;
    for (j=0;j < 3; j++) {
        if (stopsByRoute[j][i].equals(routeInfo)) {
            return stopsByRoute[j][i];
        }
    }
    return null;
}

这是我正在使用的String [] [],它被称为stopsByRoute(注意:数组不完整。它用于测试):

static String[][] stopsByRoute = {
        {"1 Timberlea Express","Main St. and Franklin Ave. Transfer Stn","Eagle Ridge Gate @ Louitit Road","Powder Station"}, 
    {"2 Thickwood Express","Main St. and Franklin Ave. Transfer Stn","Signal Rd. @ Thickwood Shopping Plaza","Westwood School" }, {"3 Morgan Heights"}};

问题是返回String []而不是返回引用。

0 个答案:

没有答案