0

I have an array list of:

ArrayList<ItemsBean> itemsList1 = new ArrayList<ItemsBean>();

I called the data from data base and added to this Arraylist

while (items.next()) {
    ItemsBean bean = new ItemsBean();
    bean.setInvNo(items.getString("Invoice_Number"));
    bean.setItemnNameDisplay(items.getString("Prodname"));
    bean.setParentobjectid(items.getString("ParentObjectID"));

    bean.setQuantityDisplay(items.getInt("Quantity"));
    bean.setProdnum(items.getInt("ProdNum"));

    itemsList1.add(bean);
}

Now I have new array list:

ArrayList<ItemsBean> newListitems2 = new ArrayList<ItemsBean>();

now I want to pass same data to this new array list in same activity

Marat
  • 6,142
  • 6
  • 39
  • 67
joy
  • 13
  • 6

2 Answers2

1

You can either use addAll() or try like this arraylist2 = arraylist1 .

addAll() is like below

arraylist2.addAll(arraylist1);

Hope this is helpful :)

Jeevanandhan
  • 1,073
  • 10
  • 18
0

ArrayList newListitems2 = new ArrayList(itemsList1); ArrayList has constructor, receiving Iterable<> as argument, so you cancreate new list with values from another list. Notice, values will remain the same, ArrayList only contains references to actual objects.

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
  • @joy how is it "no use"? This answer appears to me to be the correct answer. (Possibly with a necessary correction: `ArrayList newListitems2 = new ArrayList<>(itemsList1)`.) – Klitos Kyriacou Oct 31 '16 at 12:53