Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Norm

Thread: how could i compare aObject ( input from end user) with my existing arraylist

  1. #1
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default how could i compare aObject ( input from end user) with my existing arraylist

    how could i compare a input from end user with my arraylist....for example if i am having a university class and i have added many students over there along with details like sname, rollno, subjects, faculty ,etc.. now want to search a student by name and want wandt to display all related data of that student..... Plz reply quickly

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    Have the class implement a compare method to test the field(s) in the class. Use a loop to go through the list item by item and call the compare() method to see if the current object is the desired one.
    renuka Gawande likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    no class not having any compare method

  4. #4
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    By "use loop and go through one by one item" u mean i should iterate arraylist and then compare every existing item with input from user

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    d iterate arraylist and then compare every existing item with input from user
    Yes.
    having a university class
    It needs a method for testing its contents.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    will you please tell me how to compare it

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how could i compare aObject ( input from end user) with my existing arraylist

    What types of data needs to be compared? The technique depends on the data type.
    primitives can be compared by using operators like: ==, <=, >= != etc
    objects need to use methods to compare their contents
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 09-15-2012, 04:29 PM
  2. Compare Abstract Class Values to User input?
    By FadedAura in forum New To Java
    Replies: 16
    Last Post: 11-25-2011, 04:49 PM
  3. Replies: 0
    Last Post: 11-03-2011, 07:33 AM
  4. Replies: 3
    Last Post: 09-14-2011, 08:07 PM
  5. Replies: 13
    Last Post: 04-16-2010, 02:51 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
  •