A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/arrays_sort_object_index.htm below:

Java.util.Arrays.sort() Method

Java.util.Arrays.sort() Method Description

The java.util.Arrays.sort(Object[] a, int fromIndex, int toIndex) method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.

Declaration

Following is the declaration for java.util.Arrays.sort() method

public static void sort(Object[] a, int fromIndex, int toIndex)
Parameters Return Value

This method does not return any value.

Exception Example

The following example shows the usage of java.util.Arrays.sort() method.

package com.tutorialspoint;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

      // initializing unsorted Object array
      Object ob[] = {27, 11, 5, 44};

      // let us print all the elements available in list
      for (Object number : ob) {
         System.out.println("Number = " + number);
      }

      // sorting array from index 1 to 3
      Arrays.sort(ob, 1, 3);

      // let us print all the elements available in list
      System.out.println("Object array with some sorted values(1 to 3) is:");
      for (Object number : ob) {
         System.out.println("Number = " + number);
      }
   }
}

Let us compile and run the above program, this will produce the following result −

Number = 27
Number = 11
Number = 5
Number = 44
Object array with some sorted values(1 to 3) is:
Number = 27
Number = 5
Number = 11
Number = 44

java_util_arrays.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4