数组中的clear方法 [英] clear method in an array

查看:274
本文介绍了数组中的clear方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个清除方法来清除我拥有的数组,我已经看到使用清除方法是我所需要的,但是我似乎无法使用它?

I am trying to create a clear method that would clear the array I have, I've seen that using a clear method is what I need but I cannot seem to use it?

 list.clear();

我认为我必须做的事情:

What I think I have to do:

public void clear() {
        return doctors.clear();
    }

医生是一个数组。

但是我认为我对此有误。.

However I think I am thinking about this incorrectly..

推荐答案

一个数组不是列表。没有 clear 方法。您可以通过分配一个空引用来清除其中一个,然后让垃圾收集器来处理它……

An array is not a List. There is no clear method. You can clear one by assigning a null reference, and let the garbage collector take care of it...

yourArray = null;

或创建一个新数组,然后用新数组替换旧数组。

or create a new array, and replace the old with the new. The old one will be garbage collected.

yourArray = new YourObject [n];

这篇关于数组中的clear方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆