Doubts i stacks

If i have just created a stack using size =5 ,
Will be call that stack as empty??
But isnt it filled with values of zeroes
Also the size of the stack is it determined by “top” , or the size if have entered.
As in this case is the size 0 (top+1) or size is 5??

Also while I was writing code IDE was showing this.data can be final??

How can it be final arent we changing the value of data by pushing or isnt that counted towards “changing” please explain final in more detail

I don’t really understand the thing about final here, but yes, the stack will be called empty if top = - 1 and the size of the stack is technically the number of elements present in the stack at that time.

Can this.data attribute be final while writing our stack???

No, if data is an array it can’t be final because you are changing its contents

But even when i made it final there were no errors?

You must have made the array reference final, which works since you do not assign it to another instance of array

oh ohkay
So i can do final int[] arr;
right?

but how to make an array final so that I cannot change its contents

Honestly, I don’t know how to do that as I have never done it myself.

oh okay
Is it never needed?

no ___________________________

1 Like