美文网首页
Arrays.setAll

Arrays.setAll

作者: felixfeijs | 来源:发表于2021-04-16 10:03 被阅读0次
    public static void main(String[] args) {
        int[] ints = new int[]{1, 2, 3, 4, 5};
        Arrays.setAll(ints, new IntUnaryOperator() {
            @Override
            public int applyAsInt(int operand) {
                // 每个数进行平方
                return (ints[operand]) * (ints[operand]);
            }
        });
        System.out.println(Arrays.toString(ints));
    }

相关文章

网友评论

      本文标题:Arrays.setAll

      本文链接:https://www.haomeiwen.com/subject/wblclltx.html