Results 1 to 3 of 3
  1. #1
    TalhaS is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default Search a object in a vector

    Hi,
    I am supposed to see whether an object of a class (not Object class) is already in vector containing some objects of same class.
    for example:
    I have a class "Edge" having a sourceNode and targetNode.
    I am storing the instances of this class in an vector but before storing I need to know whether the new instance already exists in the vector or not?(edge with same source and target node)

    Can anyone let me know how can i do it?

    Thanks

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    You can use contains(Object o) method to test if that is already exists....

    Or you can start to read here for more understandable details,

    regards,
    sukatoa
    freedom exists in the world of ideas

  3. #3
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    You can also use java.util.TreeSet<E>. It does it all at once for you :)
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. Replies: 1
    Last Post: 04-17-2008, 10:10 PM
  3. URGENT: Sorting a vector of object by an element
    By doobybug in forum New To Java
    Replies: 1
    Last Post: 03-12-2008, 06:37 PM
  4. Vector help
    By king_arthur in forum New To Java
    Replies: 3
    Last Post: 01-22-2008, 07:33 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 03:33 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
  •