Answers for "sort methods java"

8

sort array java

Here’s the java program to sort an array using Arrays.sort() method.

import java.util.Arrays;
public class JavaArraySortMethod
{
   public static void main(String[] args)
   {
      String[] strGiven = {"Great Barrier Reef", "Paris", "borabora", "Florence","tokyo", "Cusco"};
      Arrays.sort(strGiven);
      System.out.println("Output(case sensitive) : " + Arrays.toString(strGiven));
   }
}
Posted by: Guest on October-23-2020
2

Arrays.sort() in java

// java program to sort strings in an alphabetical order
import java.util.Arrays;
public class SortStringAlphabeticalOrder
{
   public static void main(String[] args)
   {
      String[] strAsc = {"Bear","Fox","Deer","Cheetah","Anteater","Elephant"};
      System.out.println("Before sorting: ");
      for(String string : strAsc)
      {
         System.out.println(string);
      }
      // arrays.sort
      Arrays.sort(strAsc);
      System.out.println("-----------------------------------");
      System.out.println("After sorting: ");
      for(String str : strAsc)
      {
         System.out.println(str);
      }
   }
}
Posted by: Guest on November-29-2020
0

java sort

javaCopyimport java.util.Arrays;

public class SimpleTesting {
	public static void main(String[] args) {	
		int[] arr = new int[]{12,3,5,21,4,85,6,9,2,1};
		for (int i : arr) {
			System.out.print(i+" ");
		}
		Arrays.parallelSort(arr);
		System.out.println("\nAfter Sorting...");
		for (int i : arr) {
			System.out.print(i+" ");
		}
	}
}
Posted by: Guest on May-11-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language