Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2007, 02:25 PM
Member
 
Join Date: Jul 2007
Posts: 33
cecily is on a distinguished road
how to remove an object from the array list
I'm trying to remove a given object from the array list.
But it doesn't work.
what's the problem?
Code:
public boolean removeSomething(Student student) { student.remove(student); return true; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-01-2007, 02:36 PM
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
I would guess that the student you are trying to remove is not found in the list so it is not reomving anything.
The reasons for this could be:
1) It isn't there
2) The equals method for the student in the list and the one you are passing in do not match.
Are you creating the student manually or retrieving it from the list prior to removing it?

If that's not the case then I think you need to provide a little more information then we can give you a bit more help

Regards
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-02-2007, 03:09 PM
Member
 
Join Date: Jul 2007
Posts: 33
cecily is on a distinguished road
This is my code

Code:
public boolean remove(Student student) { if(student==null) { return false; } else { students.remove(student); return true; } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-02-2007, 03:26 PM
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
I was more after the code around what you have here.
How are you obtaining the student instance which you are passing in to this method?
Do you have a get method on this class which does :
Code:
students.get(n);
somewhere in it? like:
Code:
public Student findWithName(String name) { Student student = null; Iterator<Student> iterator = students.iterator(); while(null == student && iterator.hasNext()) { Student potential = iterator.next(); if(potential.getName.equalsIgnoreCase(name)) { student = potential; } } return student; }
If this is the case then passing the returned student into the remove function should work, however if you have created a new instance of Student then this may not work.
Can you show me the code which calls remove and also the code for Student?

Thanks.
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert List to Array Java Tip java.lang 0 04-16-2008 11:37 PM
List views, a type of object Leprechaun New To Java 2 02-06-2008 04:07 AM
Array List Problem khamuruddeen New To Java 1 12-22-2007 09:10 AM
using an Array list toad New To Java 1 11-18-2007 10:08 PM
Remove the bucket represented by the int from array barney New To Java 1 08-01-2007 09:55 AM


All times are GMT +3. The time now is 09:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org