reverse string java
String string="whatever";
String reverse = new StringBuffer(string).reverse().toString();
System.out.println(reverse);
reverse string java
String string="whatever";
String reverse = new StringBuffer(string).reverse().toString();
System.out.println(reverse);
how to reverse a string in java
public class ReverseString {
public static void main(String[] args) {
String s1 = "neelendra";
for(int i=s1.length()-1;i>=0;i--)
{
System.out.print(s1.charAt(i));
}
}
}
java reverse a string
// Library approach
public static String solution(String str) {
// StringBuilder is not thread-safe, use StringBuffer
return new StringBuffer(str).reverse().toString();
}
// DIY approach
public static String solution(String str) {
char[] chars = str.toCharArray();
for(int i = 0, j = str.length() - 1; i < j; i++, j--) {
char ch = chars[i];
chars[i] = chars[j];
chars[j] = ch;
}
return new String(chars);
}
Reverse a string in java
// reverse a string using reverse() method of StringBuilder class
class ReverseUsingReverseMethod
{
public static void main(String[] args)
{
String str = "Hello world Java";
StringBuilder sb = new StringBuilder();
// append string to StringBuilder
sb.append(str);
sb = sb.reverse();
// printing reversed String
System.out.println(sb);
}
}
java string reverse
String str = "Reverse this strings";
//for loop
for (int i = str.length() - 1; i >= 0; i--) {
System.out.print(str.charAt(i));
}
// StringBuffer for multi thread
StringBuffer sb = new StringBuffer();
sb.append(str);
System.out.print(sb.reverse().toString());
// StringBuffer for single thread
StringBuilder sb = new StringBuilder();
sb.append(str);
System.out.print(sb.reverse().toString());
Reverse a string in java
// reverse a string using character array
class ReverseUsingCharacterArray
{
public static void main(String[] args)
{
String str = "HelloWorldJava";
char[] ch = str.toCharArray();
for(int a = ch.length - 1; a >= 0; a--)
System.out.print(ch[a]);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us