How do you sort arrays in java?



How do you sort arrays in java?..

Answer / Vikas Kumar Tamta

There are several ways to sort an array in Java. One of the most common methods is using Arrays.sort():

```java
int[] arr = {5, 3, 1, 4, 2};
Arrays.sort(arr); // sorts in ascending order
System.out.println(Arrays.toString(arr)); // prints [1, 2, 3, 4, 5]

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Name the methods that used to get and set the text label displayed by a Buttonobject?

1 Answers  


Why is core java important?

1 Answers  


How to extract HashMap values?

5 Answers   Marlabs,


How many types of keywords are there?

1 Answers  


Describe method overriding

1 Answers  


How can u create the Object of class Without using "New" opertor?

3 Answers   IBM, TCS,


Can we use static class instead of singleton?

1 Answers  


How do you override a method in java?

1 Answers  


Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.

1 Answers  


How do you do descending order in java?

1 Answers  


In Java, what are public static void main string args?

2 Answers  


What is classes in java?

1 Answers  


Categories