Without going through the char sequence is there any way to reverse String
in Java
I have not seen any easy way. Here is the suitable way to do:
String d = "abcdefghij";
char b[] = new char[d.length()];// new array;
int j=0; // for the array indexing
for(int i=d.length()-1;i>=0;i--){
b[j] = d.charAt(i); // input the last value of d in first of b i.e. b[0] = d[n-1]
j++;
}
System.out.println("The reverse string is: "+String.valueOf(b));
The reverse string is: jihgfedcba
array[i] = array[n-i];
where i is the Iteration and n is the total length of array