Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I empty a primitive array?

Tags:

java

arrays

I have the following class:

public class Person {

    private String id;

    private Score[] scores;

    public Person() {
    }

    //getters and setters etc
}

How can I best remove all the Score objects within the scores array for this object?

like image 780
java123999 Avatar asked Dec 06 '25 17:12

java123999


2 Answers

re initialize the array new Score[size] or Use Arrays.fill method.

like image 107
PrabaharanKathiresan Avatar answered Dec 09 '25 06:12

PrabaharanKathiresan


I'd use Arrays.fill and fill the array with nulls.

Arrays.fill(scores, null);
like image 38
Michael Avatar answered Dec 09 '25 06:12

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!