0

Need help in getting values from arraylist then save to another arraylist (which is in another class file)

2
  • 3
    What did you try? Where are you failing? What are you expecting? What are you getting? Commented Apr 14, 2012 at 7:28
  • 1
    "Need help" Need question. As well as the answers to the 4 questions asked by @npinti Voting to close as 'not a real question' since SO is a Q&A site, not a 'tutor me in detail' site. Commented Apr 14, 2012 at 7:40

3 Answers 3

3

use Intent for passing value to another class(extends activity) intentObj.putExtras() will help.

to put:

ArrayList<String> arrayList= new ArrayList<String>();
arrayList.add("hello");
arrayList.add("there");
Intent intent = new Intent(getApplicationContext(), secondClass.class);
        intent.putStringArrayListExtra("pass_list", arrayList);
        startActivity(intent);

to get

ArrayList<String> arrayList= getIntent().getStringArrayListExtra("pass_list");
Sign up to request clarification or add additional context in comments.

1 Comment

i have no idea how to do that :\
0

Use get(index), set(index, object), insert(index, object) and add(object) methods for this.

Example:

List<String> list0 = new ArrayList<String>();
list0.add("this");
list0.add("is");
list0.add("an");
list0.add("answer");

List<String> list1 = new ArrayList<String>();
list1.add(list0.get(1));
list1.add(list0.get(3));
list1.insert(1, list0.get(0));

The resulting list1 will be: "is", "this", "answer".

Comments

0

You can use Collection class's addAll method to add all elements of an arraylist to another.

See the documentation http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#addAll%28java.util.Collection%29

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.