How to Sort 3 Integers in Java

How to Sort 3 Integers in Java thumbnail
Use Java to sort numbers.

The object-oriented language Java is a general-purpose programming language containing packages of classes that can be used to develop programs. With Java, information of any type can be stored in data structures. A fixed amount of integers can be stored in a data structure called an "array." One way to sort the data in an array is to use methods from the Arrays class. A sorted array allows the use of more efficient search algorithms to search through the array.

Things You'll Need

  • Java Runtime Environment
  • Java Development Kit
  • Java Development Environment
Show More

Instructions

    • 1

      Create a new file in your Java development program.

    • 2

      Type the following at the top of the file in your text editor:

      import java.util.Arrays;

      Java.util.Arrays contains a method that will be used to sort an array of integers.

    • 3

      Create an array of three integers, as in the following example:

      int[] array = new int[] {3, 1, 2};

    • 4

      Sort the array using the Arrays.sort method by typing the following:

      Arrays.sort(array);

      The Array.sort method sorts the integers in the array by ascending order.

Related Searches:

References

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured