Results 1 to 5 of 5
  1. #1
    johnsienk is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default How to count the number of specific object in a Vector collection?

    Dear All

    I am rather new to Java and have been stuck for hours trying to figure out one thing:

    I have a collection of different objects in a Vector<IObject> (all of these objects implement an interface I created called IObject).

    How can I count the number of specific objects in my collection?

    Let's say I have objects A,B,C that implements IObject, and objects D,E that inherit from C (and thus also implement IObject).

    I imagine a function like:

    int getObjectCount(String classNameString)
    { }

    which would return the count of objects named classNameString.

    However, if I have, say, two objects D and two objects E in my collection and then call getObjectCount(C.class.getSimpleName()) it must return '4'. (Because C is a supertype of D and E).

    Any ideas? I am slowly losing my will to live with this problem...:(

    Thanks a lot!;)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    johnsienk is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    Fubarable

    Any logical fallacy detected by you due to me posting on two different forums?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Please see my discussion in (one of ?) the cross-post(s?).

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    answered in cross-post with a somewhat enlightening discussion.

Similar Threads

  1. Replies: 8
    Last Post: 02-04-2009, 08:55 PM
  2. Either ResultSet or a specific object?
    By saul_2110 in forum JDBC
    Replies: 3
    Last Post: 12-06-2008, 07:41 AM
  3. How setting an Object to null help Garbage Collection?
    By piyu.sha in forum Advanced Java
    Replies: 3
    Last Post: 10-06-2008, 07:35 AM
  4. Search a object in a vector
    By TalhaS in forum New To Java
    Replies: 2
    Last Post: 04-30-2008, 02:05 PM
  5. How to cast an Object into a specific type (Integer/String) at runtime
    By mailtogagan@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2007, 01:04 PM

Posting Permissions

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