how to reverse a string in java | Ways of reversing a String in java | Solution
In this video i am writing program of reversing a string in java. There are many ways to reverse a string in java.
package com;
// First way of reversing a string in java (Using String Buffer)
/***public class reverse {
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer r=new StringBuffer("Human Compiler");
System.out.println(r.reverse());
}
}
//Second way of reversing a string in java (Using String Builder)
public class reverse {
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuilder r=new StringBuilder("Human Compiler");
System.out.println(r.reverse());
}
}
***/
//Third way of reversing a string in java
public class reverse {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1="";
String str="human";
int s=str.length();
for(int i=s-1;i=0;i--) { (Angle bracket missed here..)
s1=s1+str.charAt(i);
}
System.out.println(s1);
}
}
This is the code. you can just copy from here and paste it in your editor.
On this page of the site you can watch the video online how to reverse a string in java | Ways of reversing a String in java | Solution with a duration of hours minute second in good quality, which was uploaded by the user human compiler 10 November 2022, share the link with friends and acquaintances, this video has already been watched 7 times on youtube and it was liked by 0 viewers. Enjoy your viewing!