在Java中,可以使用以下方法来初始化数组并赋值:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};
int[] numbers = new int[5];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}
int[] numbers = new int[5];
Arrays.fill(numbers, 0); // 将数组所有元素的值设置为0
int[] numbers = {1, 2, 3, 4, 5};
Arrays.sort(numbers); // 对数组元素进行排序