how to check arraylist in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to check arraylist in java

i have an array list that holds numbers. i would like to check the number in my array-list against each other to add to my new array-list. For example i have [15 25 41 51 252 3]. since 15 < 25 and also less then 41 , 51, 252 i would add those to my new [15,25,41,51,252] then i would go check again. [25,41,51,252] [41,51,252] [51,252] order does matter. if i was to pull 3 and put it in front of 15 i can not use it.

19th Sep 2020, 6:24 PM
Rubii4
Rubii4 - avatar
2 Answers
0
So, are you trying to remove smallest element from the list each time you create a new list? In that case you can iterate through your list and find the smallest element. You can then call list.remove() method to remove it from the list and iterate again. In that case you don't have to create a new list each time. You can do it if you are using ArrayList class. If you are using a regular array, you can first find the smallest element, then create a new array with new length and add all elements except the smallest one to the new array.
19th Sep 2020, 7:34 PM
Aleksandrs
Aleksandrs - avatar
0
I think you are finding largest element finally.. With arrays, you can use loops and if any time a[i] <a[i+1]then add a[i], and decrease array_size value... So finally you will have your list.. By ArrayList has functions to add(), remove() and get(at index) functions... Those help for your operations... Just make attempts to code and post your try if you struck, that's help you talk more specific..
19th Sep 2020, 8:05 PM
Jayakrishna 🇮🇳