如何获取值或从嵌套数组索引并比较条件

时间:2018-04-26 16:56:16

标签: java

如何分别显示值john或mary或​​alice或bob? 来自示例嵌套数组。

SELECT 3 FROM  x_linea_cred, x_linea_cred_priv, x_clt_prd 
 WHERE x_clt_prd.r_client = @rclient AND
      (x_clt_prd.nro_prod *= x_linea_cred.nro_prod or
       x_clt_prd.nro_prod *= x_linea_cred_priv.nro_prod))

3 个答案:

答案 0 :(得分:1)

Think of the 2d array as a table (columns and rows).

So essentially you have:

John Mary
Alice Bob

Now turn that into a table using those columns and rows, you get something like this:

     0       1
  ________________
0 | John  | Mary |
1 | Alice | Bob  |

So to get "Mary", you would use kstemmers[0][1]

There are Java 8 stream solutions available, but figured it would be better for you to understand the basic concepts of 2d arrays before providing that.

答案 1 :(得分:1)

在Java 8中使用Stream:

    Arrays.stream(kstemmers)
            .map(kstemmer -> String.join(" ", kstemmer))
            .forEach(System.out::println);

答案 2 :(得分:1)

使用java8" flatMap"玩耍。一种方法可能是

List<String> collection = Arrays.stream(kstemmers).flatMap(Arrays::stream).collect(Collectors.toList());

然后遍历List