Sort an ArrayList JAVA | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Sort an ArrayList JAVA

Hi! I need help with sorting ArrayList with foreach loop: https://code.sololearn.com/chjjRqCXgo0n Also, how to display 5th element in the sorted list, delete the state at index 6 and identify which state was removed. Any help is much appreciated!

8th Feb 2018, 10:47 PM
DIY Mods
DIY Mods - avatar
1 Answer
+ 12
U can use "Arrays.sort (arrayname);" to sort the array & then pickup 5 th element by writing arrarname[4]; & U can remove the content from at index 6th by writing arrayname [6]=""; &to identify , which state content was removed , U can run a loop & putting a if condition in it ... arrayname [a].equals ("") ... if thats evaluates to true ... means index a element's content was removed
9th Feb 2018, 3:17 AM
Gaurav Agrawal
Gaurav Agrawal - avatar