how to check arraylist in java | Sololearn: Learn to code for FREE!

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.

9/19/2020 6:24:02 PM

Rubii4

2 Answers

New Answer

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.

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..