0

How can i reverse strings in java?

Example:- name would be reversed as Eman

1st Oct 2021, 8:12 AM
Baran
Baran - avatar
2 Respostas
+ 6
String str="abcdefg"; System.out.println(new StringBuilder(str).reverse().toString());
1st Oct 2021, 8:16 AM
SAN
SAN - avatar
+ 1
// Java program to ReverseString using ByteArray. import java.lang.*; import java.io.*; import java.util.*; // Class of ReverseString class ReverseString { public static void main(String[] args) { String input = "GeeksforGeeks"; // getBytes() method to convert string // into bytes[]. byte[] strAsByteArray = input.getBytes(); byte[] result = new byte[strAsByteArray.length]; // Store result in reverse order into the // result byte[] for (int i = 0; i < strAsByteArray.length; i++) result[i] = strAsByteArray[strAsByteArray.length - i - 1]; System.out.println(new String(result)); } }
1st Oct 2021, 6:14 PM
Arun Jamson
Arun Jamson - avatar