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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -