Javatpoint Logo
Javatpoint Logo

Java Program to Reverse a String Using the Stack Data Structure

The Stack is a sequential data structure that operates according to the LIFO (Last In First Out) tenet, meaning that the one that was added last is the one that is extracted first.


  1. Insert each character one at a time into the datatype character stack.
  2. Pop each character from the stack one at a time until the stack is empty.
  3. Increase the character array by one popped element.
  4. Create a string from a character array.
  5. Provide the reversed string.

The application of the aforementioned strategy is shown below.

File name:


 JavaTpoint  <- Reverse ->  tniopTavaJ
 Welcome to JavaTpoint  <- Reverse ->  tniopTavaJ ot emocleW

Time Complexity: O(n), where n is the characters count in the stack.

Space Complexity: O(n) for the stack.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA