1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Please help me with addAll method of ArrayList

Discussion in 'All Other Software' started by virkjay, Nov 1, 2007.

Thread Status:
Not open for further replies.
  1. virkjay

    virkjay Thread Starter

    Joined:
    Nov 1, 2007
    Messages:
    10
    Hi guys, I am trying to wrtie a method to add all elements of one ArrayList to another one. My code is
    import java.util.*;
    public class Purse
    {
    public Purse()
    {
    coins = new ArrayList<String>();
    }
    public void add(String coinName)
    {
    coins.add(coinName);
    }
    public String toString()
    {
    if(coins.size() == 0)
    return "Purse[]";
    String output = "Purse[";
    for(String coin : coins)
    {
    output = output + coin + ",";
    }
    return output + "]";
    }
    public void transfer1(Object other)
    {
    Purse otherPurse = (Purse) other;
    coins.addAll(otherPurse);
    other = null;
    }

    private ArrayList<String> coins;
    }

    The error i got is Purse.java:41: cannot find symbol
    symbol : method addAll(Purse)
    location: class java.util.ArrayList<java.lang.String>
    coins.addAll(otherPurse);
    ^
    1 error

    Tool completed with exit code 1

    when i tried to do in simple way it is perfectly work which is

    import java.util.*;
    public class TransferArrayList
    {
    public static void main(String args[])
    {
    ArrayList<String> list = new ArrayList();
    list.add("abc");
    list.add("fda");
    ArrayList<String> list1 = new ArrayList();
    list1.addAll(list);
    System.out.print(list1);
    list.clear();
    System.out.println(list);
    }

    }

    Can some one please tell me where i m doing mistake.
     
  2. muntez

    muntez

    Joined:
    Nov 1, 2007
    Messages:
    52
    whats this ?
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/646369

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice