Java String Examples

Java Reverse String Array Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

Add Comment

  • //The other way of reversing the string array is shown here
    public void reverseStringArray2(){
    String[] strreverse= {“abc”,”def”,”fff”,”ert”};
    System.out.println(“Array values are “+Arrays.toString(strreverse));

    for(int i=0; i<strreverse.length 2;=”” i++){=”” string=”” temp=”strreverse[i];” strreverse[i]=”strreverse[strreverse.length-i-1];” strreverse[strreverse.length-i-1]=”temp;” }=”” system.out.println(“reversed=”” array=”” values=”” are=”” “+arrays.tostring(strreverse));=”” }=””>

  • import java.util.*;

    // code by Anand B.R.(SSE)

    // code easily understood… Working fine…

    public class Test_ReversingAnArray2{

    public static void main(String args[]){

    int a[]={1,5,78,23,2,99,10,77,9,90,22};

    System.out.println(“the given array is “);

    for(int i=0;i<a.length;i++){ system.out.print(a[i]+”\t”);=”” }=”” system.out.println();=”” int=”” temp;=”” temp=”” variable=”” for=”” swapping=”” between=”” 1st=”” n=”” last=”” index=”” elements=”” int=”” i;=”” for=”” getting=”” the=”” 1st=”” index=”” int=”” j=”a.length-1;” for=”” getting=”” the=”” last=”” index=”” for(int=”” i=”0;i&lt;(a.length)/2;i++){” iterating=”” for=”” half=”” the=”” no=”” of=”” elements=”” temp=”a[i];” a[i]=”a[j];” a[j]=”temp;” j–;=”” decrementing=”” from=”” last=”” to=”” first=”” }=”” system.out.println(“the=”” new=”” again=”” reversed=”” array=”” is=”” “);=”” for(int=”” i=”0;i&lt;a.length;i++){” system.out.print(a[i]+”\t”);=”” }=”” }=”” }=””>

Sponsors

Facebook Fans