How _NOT_ to Reverse a List


While fixing a bug in our code base I came across this interesting piece of code for reversing a list. I thought I should share this work of art with others as well.

Oh forgot to say “Please don’t try this in your code base.

//List of added beans
ArrayList<SomeBean> list1 = manager.getAllValueBeans(true,idsArray, da);

ArrayList<SomeBean> list2 = manager.getAllValueBeans(true,idsArray, da);

list1=list2;

// Final list reversal
ArrayList<SomeBean> list = new ArrayList<SomeBean>();

if(dbList!=null) {

for (int i=dbList.size()-1; i>-1; i--) {

list.add(dbList.get(i));

}

Every single line of this code is a piece of art

Advertisements
How _NOT_ to Reverse a List

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s