Iulian Buga
Iulian Buga

Reputation: 325

Set a value to a group of booleans

Let's say I have 14 booleans:

Boolean pressAnimationGroup[] = { pressAnimation1,
                    pressAnimation2, pressAnimation3, pressAnimation4,
                    pressAnimation5, pressAnimation6, pressAnimation7,
                    pressAnimation8, pressAnimation9, pressAnimation10,
                    pressAnimation11, pressAnimation12, pressAnimation13,
                    pressAnimation14 };

Can I set, let's say the true value to all of them without assigning to each one of them the true value?

Something like this:

for (Boolean groupPress : pressAnimationGroup) {
                // Assign to groupPress the true value
            }

Upvotes: 0

Views: 42

Answers (2)

Giru Bhai
Giru Bhai

Reputation: 14408

Use Arrays.fill which fills the specified array with the specified element.

Arrays.fill(pressAnimationGroup, true);

Upvotes: 0

CodeWarrior
CodeWarrior

Reputation: 5176

If you wanna fill true then you can use what Giru Bhai has suggested.

In case you are using false then do nothing since boolean is by default false in java.

Upvotes: 1

Related Questions