简体   繁体   English

简化Java /处理中的数组列表

[英]simplify array list in java / processing

How can I simplify this long list.. I don't want to write Arduino.LOW so many times.. 我如何简化这个冗长的清单..我不想写Arduino.LOW这么多次。

int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };

Use a for-loop to initialize your array, if you dont know the size use an List<Integer> instead of an Array . 使用一个for循环来初始化您的数组,如果你不知道的大小使用List<Integer>而不是一个Array

int [] values = new int[14];

for(int i = 0; i < values.length; i++)
    values[i] = Arduino.LOW;

You can't. 你不能 You can use 您可以使用

import java.util.Arrays;
...
int [] values = new int[14];
Arrays.fill(values, Arduino.LOW);

But it is not exactly the same.. 但这并不完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM