how to reverse a string in java
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));
}
}
}//make a scanner object
Scanner input = new Scanner(System.in);
//take in an input string and store it inside a <String> variable
System.out.println("Enter the string: ");
String string = input.nextLine();
//convert string to character arraylist by first creating
//an array list for the characters in correct order
//and an array list for what we will use
//to store the characters in reverse order later in the code
ArrayList<Character> chars = new ArrayList<Character>();
ArrayList<Character> reversed = new ArrayList<Character>();
//put all the characters from string into chars arrayList
for (char c : string.toCharArray()) {
chars.add(c);
}
//get the size of the arraylist
Integer length = chars.size() - 1;
Integer x = 0;
//loop all the elements in the array chars into reversed arraylist in reverse order
while(x < chars.size()) {
reversed.add(chars.get(length));
length -= 1;
x += 1;
}
Also in Java:
- Title
- enumerated data types in java
- Category
- Java
- Title
- type javascirpt
- Category
- Java
- Title
- spigot spawn firework
- Category
- Java
- Title
- how to make a new arraylist java
- Category
- Java
- Title
- math minimum java
- Category
- Java
- Title
- iterate through hashmap java
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- convert string to localdatetime
- Category
- Java
- Title
- difference between java and javax
- Category
- Java
- Title
- even or odd in java
- Category
- Java
- Title
- treemap get order java
- Category
- Java
- Title
- write a java program to check whether given number is binary or not
- Category
- Java
- Title
- spigot heal player
- Category
- Java
- Title
- java stack empty
- Category
- Java
- Title
- find first non repeating character in a string
- Category
- Java
- Title
- summary of operator java
- Category
- Java
- Title
- how to break two loop in java
- Category
- Java
- Title
- FORM EN JAVA SCRIPT
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- java console text color
- Category
- Java
- Title
- gravity in java
- Category
- Java
- Title
- java script print date in YYYY-MM-DD format
- Category
- Java
- Title
- java mouseevent
- Category
- Java
- Title
- java convert a set to array
- Category
- Java
- Title
- are strings modifiable
- Category
- Java
- Title
- java stream sorted reverse
- Category
- Java
- Title
- compile java
- Category
- Java
- Title
- discord jda remove @everyone from channel
- Category
- Java
- Title
- java 8 hashmap example stackoverflow
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- android create notification
- Category
- Java
- Title
- how to create a random number in java
- Category
- Java
- Title
- how to skip a line in java
- Category
- Java
- Title
- in javascipt how to stop further page processing
- Category
- Java
- Title
- java string to boolean
- Category
- Java
- Title
- Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
- Category
- Java
- Title
- how to write sensor data into file android studio
- Category
- Java
- Title
- how to make array of objects in java and use it
- Category
- Java
- Title
- localdate to string java
- Category
- Java
- Title
- android notification addaction example
- Category
- Java
- Title
- square root java
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- java prev permutation
- Category
- Java
- Title
- how to find substring in java
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- java strin to int
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- how to add multiple filter condition in Java stream filter chain
- Category
- Java
- Title
- java date time
- Category
- Java
- Title
- Android recycleView
- Category
- Java
- Title
- how to install java 8 on terminal os
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- get spring application context
- Category
- Java
- Title
- javafx fill tableview with data
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- java calendar add minutes
- Category
- Java
- Title
- how to replace in java
- Category
- Java
- Title
- java interface
- Category
- Java
- Title
- string isEmpty java
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- prime factorization java
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- java iterate through map
- Category
- Java
- Title
- reverse array in java
- Category
- Java
- Title
- error message pushes button down
- Category
- Java
- Title
- calculate days between two dates in java
- Category
- Java
- Title
- android how to split string
- Category
- Java
- Title
- how to check if in array java
- Category
- Java
- Title
- get drawable with string android java
- Category
- Java
- Title
- how to run java program in linux server
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- java if different ways
- Category
- Java
- Title
- java ternary operator
- Category
- Java
- Title
- if else program in java
- Category
- Java
- Title
- how to initialize array in java
- Category
- Java
- Title
- enum with numbers java
- Category
- Java
- Title
- java convert string with commas to long
- Category
- Java
- Title
- split arraylist items java
- Category
- Java
- Title
- int to string java
- Category
- Java
- Title
- value receive null with post method in the java spring controller
- Category
- Java
- Title
- Java loop throug gson JsonElement
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- spring framework iterate
- Category
- Java
- Title
- jar file not running after being compiled
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- compare strings in java
- Category
- Java
- Title
- generate random number in java within a range without repeating with android studio
- Category
- Java
- Title
- set java
- Category
- Java
- Title
- sc.nextline skips
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- close searchview android java
- Category
- Java
- Title
- toString convert to long
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- check if string is decimal java
- Category
- Java
- Title
- java string indexof
- Category
- Java
- Title
- install java debian 8
- Category
- Java
- Title
- java for loop add multiple declarations
- Category
- Java