java中如何清空数组中内容呢?
下文讲述将清空数组中内容的示例分享,如下所示:
清空数组的示例
实现思路: 使用Arrays.fill()方法,即可清空数组内容例:
清空数组的示例
package com.java265.test; import java.util.Arrays; public class TestMain { public static void main(String[] args) { String[] names = {"java265.com-1", "java265.com-2", "java265.com-3"}; System.out.println("Names = " + Arrays.toString(names)); Arrays.fill(names, null); System.out.println("Names = " + Arrays.toString(names)); Integer[] numbers = {88,99,100,120,300}; System.out.println("Numbers = " + Arrays.toString(numbers)); Arrays.fill(numbers, null); System.out.println("Numbers = " + Arrays.toString(numbers)); } } -----运行以上代码,将输出以下信息---- Names = [java265.com-1, java265.com-2, java265.com-3] Names = [null, null, null] Numbers = [88, 99, 100, 120, 300] Numbers = [null, null, null, null, null]
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。