Results 1 to 9 of 9
  1. #1
    nikosv is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default Help collections

    I have two arrayLists diferent types.....
    ArrayList<Ergazomenos> erg=new ArrayList<Ergazomenos>();
    ArrayList<Proistamenos> proist=new ArrayList<Proistamenos>();



    copy(erg ,proist);
    I dont know how to copy ergazomenos to proistamenos. Can i use arraycopy?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    what exactly do you mean with "copy" ?

    ArrayList (Java Platform SE 6)

    ??

  3. #3
    nikosv is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    I want to copy all elements from arrayList erg to arrayList proist.
    thanks for the answear

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    Does class Ergazomenos extend or implement Proistamenos?
    If not then you can't (well, I suspect you could if you cheated, but you shouldn't).

  5. #5
    nikosv is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    class Proistamenos extends Ergazomenos

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    addAll() should work then.

  7. #7
    nikosv is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    I cant use addall because erg is type of Ergazomenos and proist is type of Proistamenos

    thanks anyway for your answer

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    Yes you can.
    Since Ergazomenos extends Proistamenos you can:
    Java Code:
    proist.addAll(erg);
    Because addAll() allows Collection<? extends E>...which would be Collection<? extends Proistamenos>. Which you just said Ergazomenos does.

    ETA: Oops. I misread your post.
    It's the other way around!

    In which case you have a design flaw.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    Um, you should start your own thread and not hijack someone else's.

Similar Threads

  1. Collections
    By Cbani in forum New To Java
    Replies: 3
    Last Post: 02-16-2010, 02:46 PM
  2. Collections.sort()
    By collin389 in forum Advanced Java
    Replies: 11
    Last Post: 12-31-2009, 11:03 AM
  3. Collections Help
    By Dr Gonzo in forum New To Java
    Replies: 0
    Last Post: 12-07-2008, 09:15 PM
  4. Collections Sort
    By senthil_jr in forum Advanced Java
    Replies: 2
    Last Post: 06-04-2008, 08:11 AM
  5. Performance Of Collections
    By thomasprabu in forum Advanced Java
    Replies: 0
    Last Post: 01-05-2008, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •