final List<Toy> toys = Arrays.asList("new Toy(1)", "new Toy(2)");
final List<Item> itemList = toys.stream()
.map(toy -> {
return Item.from(toy); //Creates Item type
}).collect(Collectors.toList);
Run Code Online (Sandbox Code Playgroud)
上面的代码可以正常工作,并将从玩具列表中生成项目列表。
我想做的是这样的:
final List<Item> itemList = toys.stream()
.map(toy -> {
Item item1 = Item.from(toy);
Item item2 = Item.fromOther(toy);
List<Item> newItems = Arrays.asList(item1, item2);
return newItems;
}).collect(Collectors.toList);
Run Code Online (Sandbox Code Playgroud)
或者
final List<Item> itemList = toys.stream()
.map(toy -> {
return Item item1 = Item.from(toy);
return Item item2 = Item.fromOther(toy); //Two returns don't make sense but just want to illustrate the idea.
}).collect(Collectors.toList); …
Run Code Online (Sandbox Code Playgroud) 如果我有一个列表,如:
List = [12,6,3,5,1.2,5.5]
Run Code Online (Sandbox Code Playgroud)
有没有办法可以检查所有数字是否都是整数?我试过类似的东西
def isWhole(d):
if (d%1 == 0 ) : for z in List return true.
Run Code Online (Sandbox Code Playgroud)
这显然是非常错误的.我能做什么?