Java – How to get size of Stack

Size of Stack can be find by size() method. In size method, it will return value in integer.

Example of finding size in Stack in Java

Stack<String> sk=new Stack<String>();

sk.push("a");
sk.push("c");
sk.push("e");
sk.push("d");

int sizeOfStack=sk.size();

System.out.println("Size of Stack :"+sizeOfStack);

Output

Size of Stack :4

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post