?
Solved

how can i assign one arraylist  to another

Posted on 2004-11-30
6
Medium Priority
?
897 Views
Last Modified: 2008-03-06
 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++)
                {
                                                ...........................
            }

            }

0
Comment
Question by:chaitu chaitu
  • 4
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12705377
You can either assign or copy (of which you gave an example). What is the difficulty?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 12705400
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
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 12705430
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Author Comment

by:chaitu chaitu
ID: 12705463
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12705464
See my code above. You could also simply assign getViewChargesList to 'cl' in the else block if you want
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12706027
:-)

Actually you can do just

cl = new ArrayList(breakBulkHouseModel.getViewChargesList());
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question