Java Online Compiler
Example: String Reverse in Java using ArrayList Object | ListIterator
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// String Reverse in Java using ArrayList Object | ListIterator import java.util.*; import java.util.Scanner; public class Main { // It's the driver function public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a string to make reverse::\n"); String x=in.nextLine(); // it will create a character array of the input string char[] charArr=x.toCharArray(); List<Character> ArrList=new ArrayList<>(); for (char c:charArr) { ArrList.add(c); } // It will reverse the input string System.out.print ("The reverse of the string is:: "); Collections.reverse(ArrList); ListIterator list = ArrList.listIterator(); while (list.hasNext()) { System.out.print(list.next()); } System.out.println("\n"); } }
Welcome programmers
Output
Clear
ADVERTISEMENTS