How To Use The rt() Method In Java
Maybe your like
ExploreEXPLORE THE CATALOGSupercharge your career with 700+ hands-on coursesView All CoursesPythonJavaJavaScriptCReactDockerVue JSRWeb DevDevOpsAWSC#LEARNING TOOLSExplore the industry's most complete learning platformCoursesLevel up your skillsSkill PathsAchieve learning goalsProjectsBuild real-world applicationsMock InterviewsNewAI-Powered interviewsPersonalized PathsGet the right resources for your goalsLEARN TO CODECheck out our beginner friendly courses.PricingFor BusinessResourcesNewsletterCurated insights on AI, Cloud & System DesignBlogFor developers, By developersFree CheatsheetsDownload handy guides for tech topicsAnswersTrusted answers to developer questionsGamesSharpen your skills with daily challengesSearchCoursesLog InJoin for freeHow to use the Arrays.sort() method in Java
The built-in java.util.Arrays class has a method called sort() which can be used to sort an array in-place.
Syntax
If starting_index and ending_index are not specified, the whole array is sorted.
Code
The following code snippet demonstrates how Arrays.sort() can be used to sort an integer array:
import java.util.Arrays; class Program { public static void main( String args[] ) { int [] arr = {5, -2, 23, 7, 87, -42, 509}; System.out.println("The original array is: "); for (int num: arr) { System.out.print(num + " "); } Arrays.sort(arr); System.out.println("\nThe sorted array is: "); for (int num: arr) { System.out.print(num + " "); } } }RunThe code snippet below uses the optional starting and ending indexes to sort the array within the specified bounds only:
import java.util.Arrays; class Program { public static void main( String args[] ) { int [] arr = {5, -2, 23, 7, 87, -42, 509}; System.out.println("The original array is: "); for (int num: arr) { System.out.print(num + " "); } Arrays.sort(arr, 3, 6); System.out.println("\nThe sorted array (from position 3 to 6) is: "); for (int num: arr) { System.out.print(num + " "); } }}RunRelevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reservedTag » How To Sort An Array In Java
-
rt() In Java With Examples - GeeksforGeeks
-
How To Sort An Array In Java - Javatpoint
-
How To Sort An Array In Java - Tutorial With Examples
-
How To Sort An Array In Java - Video & Lesson Transcript
-
What Is Sort Array In Java: Everything You Need To Know | Simplilearn
-
Java Sort Array – How To Reverse An Array In Ascending Or ...
-
Sort An Array In Java - Stack Overflow
-
How To Sort An Array In Descending Order In Java? Example Tutorial
-
JavaScript Sorting Arrays - W3Schools
-
How To Sort An Array In Java Without Using The Sort() Method
-
How To Sort An Array In Java - Linux Hint
-
Sort An Array - LeetCode
-
Arrays (Java Platform SE 7 ) - Oracle Help Center
-
How To Sort An Array In Java - Code |Interviewkickstart