Answers for "sort alphabetically in java"

4

java sort string characters alphabetically

// java sort string characters alphabetically
import java.util.Arrays;
public class CharactersAlphabetically
{
   public static void main(String[] args)
   {
      String strInput = "flowerbrackets";
      // converting string to char array
      char[] ch = strInput.toCharArray();
      // sorting char array
      Arrays.sort(ch);
      // converting char array to string
      String strSorted = String.valueOf(ch);
      System.out.println("sort string characters alphabetically: " + strSorted);
   }
}
Posted by: Guest on February-19-2021
2

Arrange words of a sentence in alphabetical order in java

// Arrange words of a sentence in alphabetical order in java
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class ArrangeInAlphabeticalOrder 
{
   public static void main(String[] args) 
   {
      Set set = new TreeSet();
      String strInput = "hi all welcome to flower brackets blog";
      System.out.println("Before arranging sentence in alphabetical order: " + strInput);
      StringTokenizer strToken = new StringTokenizer(strInput," ");
      while(strToken.hasMoreElements())
      {
         set.add(strToken.nextElement());
      }
      System.out.println("After arranging sentence in alphabetical order: " + set);
   }
}
Posted by: Guest on February-22-2021

Code answers related to "sort alphabetically in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language