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 ?
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.
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 ?
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!
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.
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.
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.
syed bhai thanks for your reply i want to delete the fields from the student object such as id or name etc.
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.
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
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.'
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!
not student object but ya i want to remove values from 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!
Thanks for all replying me and helping me i solved the problem
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!