Sort Array in Ascending Order

--

Here array elements are arranged in the lowest to the highest order. To do this, we can use the following ways.

  • Using the sort() Method
  • Using the for loop

Using the sort() Method

example:

output:

Java provides user-defined class named Array in java.util package. It provides sort() to sort an array in ascending order.

Using the for Loop

example:

output:

In here we use two for loops. The outer loop will select an element, and the inner loop allows us to compare the selected element with the rest of the elements.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tharuksi Gunasekara
Tharuksi Gunasekara

Written by Tharuksi Gunasekara

I am an undergraduate of faculty of Information technology in university of Moratuwa

No responses yet

Write a response