Answers for "string sort function in java"

2

How to sort a string array in java

// how to sort string array in java without using sort method
import java.util.Arrays;
public class SortStringArray
{
   public static void main(String[] args)
   {
      String[] strPlaces = {"Great Barrier Reef", "Paris", "BoraBora", "Florence","Tokyo", "Cusco"};
      int size = strPlaces.length;
      for(int a = 0; a < size - 1; a++)
      {
         for(int b = a + 1; b < strPlaces.length; b++)
         {
            if(strPlaces[a].compareTo(strPlaces[b]) > 0)
            {
               String temp = strPlaces[a];
               strPlaces[a] = strPlaces[b];
               strPlaces[b] = temp;
            }
         }
      }
      System.out.println(Arrays.toString(strPlaces));
   }
}
Posted by: Guest on December-09-2020
0

sort string java

import java.util.Arrays;

public class Test
{
    public static void main(String[] args)
    {
        String original = "edcba";
        char[] chars = original.toCharArray();
        Arrays.sort(chars);
        String sorted = new String(chars);
        System.out.println(sorted);
    }
}
Posted by: Guest on April-18-2021
1

sort a string array java

String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop","Neo4j"};
Arrays.sort(myArray);
System.out.println(Arrays.toString(myArray));
Posted by: Guest on September-29-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language