how can i assign one arraylist to another

 if(breakBulkHouseModel.getChargesList()!=null)
                   {
                        breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());
                                                                             
                   }
                    else
                {
                }


                       

                 
        how can i assign one arraylist  to another if  breakBulkHouseModel.getChargesList() is null
like breakBulkHouseModel.getChargesList() =breakBulkHouseModel.getViewChargesList();


after that i will do like this

if(breakBulkHouseModel.getChargesList() != null)
              {
             for(int j=0;j<breakBulkHouseModel.getChargesList().size();j++)
                {
                                                ...........................
            }

            }

LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You can either assign or copy (of which you gave an example). What is the difficulty?
0
CEHJCommented:
Oh i think i see

List cl = breakBulkHouseModel.getChargesList();
if (cl != null) {
      // copy it
}
else {
      cl = new ArrayList(breakBulkHouseModel.getViewChargesList().size());
      cl.addAll(breakBulkHouseModel.getViewChargesList());
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chaitu chaituAuthor Commented:
in some cases   breakBulkHouseModel.getChargesList() will come null then i want to assign   breakBulkHouseModel.getChargesList() to  breakBulkHouseModel.getViewChargesList() ;


in my application i am doing

 breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());

if  breakBulkHouseModel.getChargesList() will come null i am getting nullpointer exception;

at that time i want assign

tChargesList() =ViewChargesList();

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

chaitu chaituAuthor Commented:
if(breakBulkHouseModel.getChargesList()!=null)
                   {
                        for(Iterator k=breakBulkHouseModel.getChargesList().iterator();k.hasNext();)
                        {
                                HouseDocumentCharges      viewCharges      =      (HouseDocumentCharges)k.next();
                             if(breakBulkHouseModel.getViewChargesList()!=null)
                             {
                                for(Iterator j=breakBulkHouseModel.getViewChargesList().iterator();j.hasNext();)
                                {
                                     HouseDocumentCharges      charges      =      (HouseDocumentCharges)j.next();
                                    if(charges.chargeId.equals(viewCharges.chargeId) || !charges.chargeId.equals("045"))
                                    {
                                        j.remove();
                                        continue;
                                    }
                                           
                                }
                             }                            
                        }
                        if(breakBulkHouseModel.getChargesList() != null && breakBulkHouseModel.getViewChargesList() != null)
                        breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());
                                                                             
                   }
                    else
                  breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());

              if i am doing  like this i am getting nullpointer exception because  breakBulkHouseModel.getChargesList() comes nulll

              at that time i want to assign

breakBulkHouseModel.getChargesList() =breakBulkHouseModel.getViewChargesList();
                                                                             
                 
                       

                 
         if(breakBulkHouseModel.getChargesList() != null)
              {
             for(int j=0;j<breakBulkHouseModel.getChargesList().size();j++)
                {
                    houseDocumentCharges =(HouseDocumentCharges)breakBulkHouseModel.getChargesList().get(j);

                    }

                }
0
CEHJCommented:
See my code above. You could also simply assign getViewChargesList to 'cl' in the else block if you want
0
CEHJCommented:
:-)

Actually you can do just

cl = new ArrayList(breakBulkHouseModel.getViewChargesList());
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.