Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 28th, 2012, 10:47 PM
anonymousme anonymousme is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 38 anonymousme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 46 m 22 sec
Reputation Power: 1
ArrayList Remove Method

I am trying to write a remove method for an ArrayList class. I cannot use any built-in Java collections. I have been trying for at least a few days trying to figure this algorithm out, but nothing is working.

Here is what I have so far...

Code:
//Remove the element at the given index and returns it.
	public E remove(int index)
	{
		
		E result = get(index);
	
		for (int x = index; x < count - 1; x++)
		{
			data_store[count - 2] = data_store[count - 1] ; 
		}
		count --;
		return result;
	
	}


Thanks.

Reply With Quote
  #2  
Old October 29th, 2012, 08:18 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,824 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 8 h 43 m 32 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
You could create a temporary ArrayList, copy everything except the element into it, and then rearrange the name of the list.

Reply With Quote
  #3  
Old October 29th, 2012, 10:22 AM
anonymousme anonymousme is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 38 anonymousme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 46 m 22 sec
Reputation Power: 1
Quote:
Originally Posted by bullet
You could create a temporary ArrayList, copy everything except the element into it, and then rearrange the name of the list.


Thank you.

I tried this.

[/CODE] public E remove(int index)
{


E result = data_store[index];
E newArray[] = null;
E temp = newArray[index];
for (int x = index; x < count - 1; x++)
{
data_store[ count -2 ] = data_store[ count - 1] ;
}
temp = data_store[count];
count--;
return result;


}[/CODE]

Is this what you meant? Thanks again.

Reply With Quote
  #4  
Old October 29th, 2012, 01:06 PM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,824 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 8 h 43 m 32 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
In what class is the remove method?

Reply With Quote
  #5  
Old October 29th, 2012, 02:57 PM
anonymousme anonymousme is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 38 anonymousme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 46 m 22 sec
Reputation Power: 1
Quote:
Originally Posted by bullet
In what class is the remove method?



Code:
public class MyArrayList<E> implements MyListInterface<E>


All code must be in the MyArrayList class.

The one method I am having trouble with is the remove method.

Reply With Quote
  #6  
Old October 29th, 2012, 06:53 PM
anonymousme anonymousme is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 38 anonymousme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 46 m 22 sec
Reputation Power: 1
Quote:
Originally Posted by anonymousme
Code:
public class MyArrayList<E> implements MyListInterface<E>


All code must be in the MyArrayList class.

The one method I am having trouble with is the remove method.


I figured it out. Thanks for your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > ArrayList Remove Method

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap