How to check if a list is sorted in java?



How to check if a list is sorted in java?..

Answer / Vaibhav Tripathi

In Java, you can check if a List is sorted by iterating through its elements and comparing adjacent ones. Here's a simple example: `List<Integer> list = ...; Collections.sort(list); boolean isSorted = true; for (int i = 1; i < list.size(); i++) { if (list.get(i) < list.get(i - 1)) { isSorted = false; break; } }`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are the different ways of implementing thread? Which one is more advantageous?

1 Answers  


what is the Arraylist limit (maximum) by default ?

13 Answers   Fidelity, PlanetSoft, Wipro,


Why heap memory is called heap?

1 Answers  


What is a private class in java?

1 Answers  


Explain a situation where finally block will not be executed?

1 Answers  


Can we override a variable in java?

1 Answers  


Do you know thread pools?

0 Answers   BMC,


What is json parser in java?

1 Answers  


What are the difference between string, string builder, and string buffer in java?

1 Answers  


What is a bufferedreader?

1 Answers  


What is string variable?

1 Answers  


How many bits is a 64 bit byte?

1 Answers  


Categories