Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Delete data from inside the object

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Delete data from inside the object

    can somebody tell me how to delete the data from inside the object ? if object contain the record of more than two students like id,name, etc. i have to delete this values from the object ? so how can i do that ?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Delete data from inside the object

    What exactly do you mean when you say "delete this values"? Are you asking how to remove them from a databse? A text file? The code? Something else?

    It would be helpful if you provided an SSCCE demonstrating exactly what you're doing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: Delete data from inside the object

    It all depends on how your object is setup. Does your object contain an array of students or a linked list of students or something completely different? It all depends on the stru/cture of your object on how you will be removing information from it.

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Delete data from inside the object

    Sir thank you for your reply i have created the list of the student List<Student> lstStudent = new ArrayList<Student>(); and i have added item in this list like id ,name etc.so i remove this item from the object.

  5. #5
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Delete data from inside the object

    Hello.
    Your question is ambiguous (unclear).
    Suppose you have collection say list. In this list you have added various objects of type Student. In a Student object you have id and name.
    Now tell us what do you want to delete.
    A Student object from the list or a field from student object such as id or name.
    If it is former then you can do it. But if it is latter then you cannot.

    Syed.

  6. #6
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Delete data from inside the object

    syed bhai thanks for your reply i want to delete the fields from the student object such as id or name etc.

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Delete data from inside the object

    I think we're confused by the word 'delete.' You can't change the structure of an existing class instance. For example if you have an instance of Student, student, that has fields, id, name, age, etc., you can't 'delete' those fields. You can change the value of those fields, including setting them to null or zero as appropriate. To do that:

    Obtain the desired student instance from the ArrayList of Student objects,
    Use the instance to set the fields as desired:

    student.setID( 0 );

    etc.

  8. #8
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Delete data from inside the object

    Thanks GregBrannon for your reply i tell you more specifically lets say i have student object s1 having id=101, name =mack fields.Your are right but i am talking about to delete the values present in those fields.so how can i delete those fields

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Delete data from inside the object

    Reread my post, starting with "To do that:"

    If there's something in the simple instructions I've given that you don't understand or don't know how to do, then ask specifics rather than general, ambiguous questions, like "How do I do that?" And please stop using the word, 'delete.' I think we've established that you can't delete, and you mean 'change.'

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Delete data from inside the object

    Are you asking how to remove a student with a specific set of values from the list?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Delete data from inside the object

    not student object but ya i want to remove values from the object

  12. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Delete data from inside the object

    Then I echo what has been said already: what you're asking doesn't make any sense. Why do you want to do this?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Delete data from inside the object

    Thanks for all replying me and helping me i solved the problem

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Delete data from inside the object

    Quote Originally Posted by ankityadav View Post
    Thanks for all replying me and helping me i solved the problem
    How did you solve it? I'm pretty curious what the actual question was...
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Search and delete data to a Text file in GUI
    By Nathanlll in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 24th, 2013, 04:36 PM
  2. How do I delete an object from my program?
    By Skynet928 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 19th, 2013, 08:13 PM
  3. How to delete several data in database using java?
    By shihab2555 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 8th, 2012, 04:57 PM
  4. How to Delete selected table data from DB???? HELP
    By lanepulcini in forum JDBC & Databases
    Replies: 0
    Last Post: February 21st, 2012, 07:07 PM
  5. How to delete data from php through GUI in Java?
    By BluXit in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2010, 09:41 AM