Re-ordering an ArrayList in a specific order in java -
i have 2 following arraylists
:
orderlist=[htc, apple, blackberry, karbon]
dynamiclist=[nokia, samsung, apple, htc, blackberry, micromax, lenova, karbon]
while passing dynamiclist
back-end, want re-order elements in dynamiclist
based on order in orderlist
in following way.
dynamiclist=[htc, apple, blackberry, karbon, nokia, samsung, micromax, lenova]
example :
dynamiclist=[nokia, samsung, blackberry, micromax, lenova, karbon]
should ordered follow
dynamiclist=[blackberry, karbon, nokia, samsung, micromax, lenova]
where should start ?
create new list finallist
. loop on orderlist
, check if element present in dynamiclist
. if is, add()
finallist
, remove dynamiclist
.
once you're done looping on orderlist
, add remaining elements of dynamiclist
finallist
.
Comments
Post a Comment