怎么把Stream流里面的数据添加到已有的数组中呢,代码在图片

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

img


import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        AtomicInteger my_index = new AtomicInteger();
        int[] arr2 = Arrays.stream(arr).filter(item -> {
            int index = my_index.getAndIncrement();
            return (index >= 2 && index < 7) ? true : false;
        }).toArray();
    }
}

知识点:
1、流中使用索引的方法,使用的是一个自增序列,假装它是这个流的索引;
2、通过filter自定义过滤逻辑替代skip和limit。