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));
}
}
}
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);
}
}
string reverse in java
String str = "Hello";
String reverse(String str){
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.reverse();
return sb.toString();
}
Reverse a string in java
// reverse a string using toCharArray() method
class ReverseUsingToCharArrayMethod
{
public static void main(String[] args)
{
String str = "Hello World Java";
char[] chTemp = str.toCharArray();
int left, right = 0;
right = chTemp.length - 1;
for(left = 0; left < right ; left++, right--)
{
// swap values
char temp = chTemp[left];
chTemp[left] = chTemp[right];
chTemp[right]=temp;
}
for(char c : chTemp)
System.out.print(c);
System.out.println();
}
}
Java reverse string array
// reverse string array in java using collections
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ReverseStringArrayUsingCollections
{
public static void main(String[] args)
{
// creating list of strings
List<String> li = new ArrayList<String>();
li.add("java");
li.add("core");
li.add("world");
li.add("hello");
System.out.println("Given list: " + li);
Collections.reverse(li);
System.out.println("After using collections: " + li);
}
}
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