问题

我想连接每个这些数组,然后迭代结果集合.

         String[] type = {"school", "home"};
        String[] place = {"tokyo ", " New York"};
        String[] date = {"Sep", "Feb"};


        for(String name: type) {
            Assert.assertFalse(isValid(name));
        }
        for(String name: place) {
            Assert.assertFalse(isValid(name));
        }
        for(String name: date) {
            Assert.assertFalse(isValid(name));
        }

 

  最佳答案

不一定要分离出来,但也许你会对这样的事情感兴趣:

 Stream.of(type, place, date) //Stream<String[]> example [ [a,b], [c,d] ]
      .flatMap(Stream::of)   //Stream<String>   example [ a, b, c, d ]
      .forEach(name -> Assert.assertFalse(isValid(name));
 

类似于

 for (String[] arr : Arrays.asList(type,place,date)){
    for(String name : arr){
        Assert.assertFalse(isValid(name)
    }
}
 

  相同标签的其他问题

java