Opening Hours :7AM to 9PM
import java.util.Arrays; public class SortArray { public static void main(String[] args) { int[] nums = {5, 8, 1, 3, 9, 6}; Arrays.sort(nums); System.out.println("Sorted Array: " + Arrays.toString(nums)); } }This will give the output:
import java.util.Arrays; public class SortArray { public static void main(String[] args) { String[] words = {"c", "a", "e", "b", "d"}; Arrays.sort(words); System.out.println("Sorted Array: " + Arrays.toString(words)); } }This will give the output:
import java.util.Arrays; class Employee implements Comparable<Employee>{ int id; String name; int age; public Employee(int id, String name, int age) { this.id = id; this.name = name; this.age = age; } @Override public int compareTo(Employee o) { return name.compareTo(o.name); } } public class SortArray { public static void main(String[] args) { Employee[] employees = { new Employee(1,"John",30), new Employee(2,"Mike",25), new Employee(3,"Bob",35) }; Arrays.sort(employees); for (Employee e : employees) { System.out.println(e.name); } } }This will give the output: