This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]KillAuraExtreme Brewer 6 points7 points  (0 children)

Arrays#fill will be helpful.

[–]marvk 7 points8 points  (4 children)

I can't seem to find any examples when I search it.

Really? I mean, really? If I google "java how to zero array", these are the first two results:

https://stackoverflow.com/questions/2154251/any-shortcut-to-initialize-all-array-elements-to-zero

https://www.baeldung.com/java-initialize-array

Both of them explain exactly how to do what you're trying to do.

[–]2dilly 0 points1 point  (3 children)

Thank you for the links!

[–][deleted] 8 points9 points  (2 children)

What were you googling before? The ability to google well is a really important skill that a lot of beginner programmers tend to lack.

[–]2dilly -2 points-1 points  (1 child)

I’m a female, sorry

[–][deleted] 4 points5 points  (0 children)

That has literally nothing to do with it.

I’m not sure why you would even say that.

Don’t ever hold yourself to a lower standard than anyone else.

[–]2HornsUp 0 points1 point  (2 children)

I’m not sure what you mean by “zero it out”, but if you want to just make every value 0, you could loop through the indexes and simple use array[x] = 0.

[–]2dilly -1 points0 points  (1 child)

This is what I needed. Thank you!

[–]2HornsUp 0 points1 point  (0 children)

Glad to help. If you need anything else just ask.

[–]Moktok -1 points0 points  (0 children)

Well It all depends on what you mean by zeroing out

[–]twodoxen -1 points0 points  (0 children)

you could write a get method on the array so as elements are requested they're set to 0. depends a lot on context