Write a java program to sort the give string

Here we explain how to write a program to sort the give string. Suppose  that there is array of string is StringArray which contain the value as java, fore, cast, for, you. The java class StringSortingTest.java is use to sort the give string. So see the code for this class as 


StringSortingTest.java

package com.javaforecast4u;

public class StringSortingTest {
    public static void main(String args[])
    {
        
         String StringArray[]={"java","fore","cast","for","you"};
        int n=StringArray.length;
       String temp;
      for(int i=0;i<n;i++)
         {
            for(int j=i+1;j<n;j++)
             {
                if(StringArray[i].compareTo(StringArray[j])>0)
                 {
                 temp=StringArray[i];
                 StringArray[i]=StringArray[j];
                 StringArray[j]=temp;
                 }
             }
         }
         for(int i=0;i<n;i++)
         {
             System.out.println(StringArray[i]);
         }
    }

}

 Output:


cast
for
fore
java
you

49 comments :

  1. I find this blogger an inspiration and is definitely worth following. I've became a subscriber too, so please keep me updated. thanks once again.

    Chuck
    www.gofastek.com

    ReplyDelete
  2. interesting details! keep sharing articles like this. Kudos!

    www.triciajoy.com

    ReplyDelete
  3. You have a wonderful blog. This is really worth to read and it helps a lot of people to learn new information. Please keep on posting. Thank you.

    Sienna
    www.gofastek.com

    ReplyDelete
  4. this java program is awesome stuff. thanks for sharing
    solution manual book

    ReplyDelete
  5. Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


    ufgop.org
    ufgop.org

    ReplyDelete

  6. Having read this I believed it was very informative. I appreciate you spending some time and energy to put this information together. I once again find myself spending a lot of time both reading and commenting. But so what, it was still worthwhile! outlook 365 sign in

    ReplyDelete