在Java中,可以使用以下方法來(lái)初始化數(shù)組并賦值:
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); // 將數(shù)組所有元素的值設(shè)置為0
int[] numbers = {1, 2, 3, 4, 5};
Arrays.sort(numbers); // 對(duì)數(shù)組元素進(jìn)行排序