How to reverse a string in java
👋 Hey there! I’m Shohanur Rahman!
I’m a backend developer with over 5.5 years of experience in building scalable and efficient web applications. My work focuses on Java, Spring Boot, and microservices architecture, where I love designing robust API solutions and creating secure middleware for complex integrations.
💼 What I Do Backend Development: Expert in Spring Boot, Spring Cloud, and Spring WebFlux, I create high-performance microservices that drive seamless user experiences. Cloud & DevOps: AWS enthusiast, skilled in using EC2, S3, RDS, and Docker to design scalable and reliable cloud infrastructures. Digital Security: Passionate about securing applications with OAuth2, Keycloak, and digital signatures for data integrity and privacy. 🚀 Current Projects I’m currently working on API integrations with Spring Cloud Gateway and designing an e-invoicing middleware. My projects often involve asynchronous processing, digital signature implementations, and ensuring high standards of security.
📝 Why I Write I enjoy sharing what I’ve learned through blog posts, covering everything from backend design to API security and cloud best practices. Check out my posts if you’re into backend dev, cloud tech, or digital security!
using StringBuilderpublic class Main { public static void main(String[] args) { String string = "shohan"; StringBuilder sb = new StringBuilder(string); System.out.println(sb.reverse()); } }using looppublic class Main { public static void main(String[] args) { String string = "shohan"; String reverse = ""; for (int i = string.length() - 1; i >= 0; i--) { reverse = reverse + string.charAt(i); } System.out.println(reverse); } }using recursionpublic class Main { public static void main(String[] args) { Main main = new Main(); String string = "shohan"; String reverse = main.reverse(string); System.out.println(reverse); } public String reverse(String str) { // Base case: If string is empty or has a single character, return it as is if (str.isEmpty() || str.length() == 1) { return str; } else { /* Recursive case: 1. Extract the first character and store it. 2. Recursively reverse the remaining substring (excluding the first character). 3. Append the first character to the reversed substring. */ return reverse(str.substring(1)) + str.charAt(0); } } }