Java Stack push() vs add()

Kalyanaraman Santhanam:

Edit: Will I encounter any issues if I use add(…) instead of

Definitly, you will not encounter any issues, because add is part of List interface as well as the Stack, but you should to notice the further readability of your code and your intentions in it by other programmers. push method will give them a clue that they’re using the Stack object, they will know certantly what to expect from. Also notice that push has different return value than add (the former has “pushed object” type and the latter just a boolean response)

Leave a Comment