java - 是否可以为 Int 数组中的所有数字赋值?

标签 java arrays int

int[] high = {2,3,4,5,6};

可以给数组一个恒定的值,比如说 -1 吗?清除 {2,3,4,5,6} 都等于 -1。

最佳答案

您可以使用 Arrays.fill(int[] a, int val) java.util.Arrays 中的方法,它用值 val 填充数组 a。 在你的情况下:

int[] high = new int[5]; 
Arrays.fill(high, -1);

关于java - 是否可以为 Int 数组中的所有数字赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20174081/

相关文章:

java - Eclipse 中有用于将标签应用于文件的插件吗?

java - 从 getCursorName 函数读取数据时出现异常 "positioned update not supported"

c++ - 确定数组索引到哪个数组被填充?

python - Python 中的 int 对象可以在函数内部变得可迭代吗?

python - 类型错误 : Can't convert 'int' object to str implicitly

java - 从 api 获取数据适用于 https api,但不适用于 http api

java - 在一个循环中使用 HashMap 的第一个非重复字符?

arrays - Haskell 位数组

Javascript 数组奇怪的行为

java - 在 Java 中使用常量 : How to log the name given to them?