Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 1st, 2005, 9:20 AM   #11
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
for(int i=0;i<points.size();i++) 
{
	g.fillOval(
				((MyPoint)points.get(i)).x,
				((MyPoint)points.get(i)).y,
				dotSize, dotSize);
}

try that

JD
JDStud6 is offline   Reply With Quote
Old Dec 1st, 2005, 9:21 AM   #12
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
Why would he want to do that?
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 1st, 2005, 9:26 AM   #13
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
are you asking because you don't know, or because you think he should know?

haha

JD
JDStud6 is offline   Reply With Quote
Old Dec 1st, 2005, 9:51 AM   #14
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
I'm asking because he doesn't know, which is why I suggested that he read the API instead of just giving him code.. then he may have been able to figure out on his own how to create the constructor, which libraries were necessary, and why one needs to do what you told him to do. And if not, he would have had questions about reading APIs, which would have allowed him to learn more on his own.

So to answer your question, I asked because I think he should know why you are recommending that he do what you said to do. Otherwise the next time that he goes to .get something, he will be stuck again, having learned nothing now.

If it were me, I would have explained that an arraylist is really just a list of pointers that point to objects in memory, and it has no idea what kind of objects that they are. In order to use those objects, one must cast the object (which is just a way of telling the arraylist what it is) back into what they originally were so that the arraylist knows what to do with them. This is a crude (and not completely correct) explanation, but usually enough to make people understand.

I would also explain that depending on the version of java one is using, and that since it is bad practice to store more than one datatype in a single collection, one can save themselves the trouble of having to tell the arraylist what it is removing each time by telling it ahead of time what sort of objects it will be holding, and one can do that (for example), in the following manner:
ArrayList<myObject> a = new ArrayList();

Now my arraylist knows it is only going to hold myObjects, and won't let you put anything else in there but myObjects. It will always know what to do with them.

*****

But that is just me...
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 1st, 2005, 9:57 AM   #15
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
uhh....yea, what he said

JD

(ps - if you don't understand, research 'casting' and look at the API for arraylist)
JDStud6 is offline   Reply With Quote
Old Dec 1st, 2005, 1:18 PM   #16
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 3 Writlaus is on a distinguished road
Ah thank you all, it finally works. Seeing those dots appear is a beautiful sight...

I knew it had to do with the fact that I didn't specify what type of object was going to be in the ArrayList, but I didn't know how to specify that. But now I do, so it's all good =)
Writlaus is offline   Reply With Quote
Old Dec 1st, 2005, 2:38 PM   #17
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Quote:
Originally Posted by andro
Make sure to import java.util.ArrayList.

ArrayList<Integer> myList = new ArrayList<Integer>();

and the ArrayList api...
http://java.sun.com/j2se/1.5.0/docs/...ArrayList.html
Thanks for your help. Is it possible to do the equivalent of this but store primitive int data types, for example ArrayList<int>? I looked up "autoboxing" but I'm not sure that's what I want. I need something that will run very fast, which is why I don't want to have to keep converting from Integer to int and so forth.
titaniumdecoy is offline   Reply With Quote
Old Dec 1st, 2005, 7:31 PM   #18
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 309
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
Integer is int.
andro is offline   Reply With Quote
Old Dec 1st, 2005, 7:37 PM   #19
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
No, one is a basic data type and the other is an object.
titaniumdecoy is offline   Reply With Quote
Old Dec 1st, 2005, 8:17 PM   #20
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
There are a couple of approaches that I can think of, but all of them require some sort of conversion, whether it is handled by the programmer, or by the JVM, the conversions are still taking place. And it could very well be that I don't have a clue as to what I am talking about.. in which case this is an opportunity for me to learn also.

You can use autoboxing, which only means that the conversion is done for you. It is still happening, and it may or may not be very efficient.

You can create your own add/get methods that do the conversions for you.

How big of a list of are you wanting to handle? Over a million? 3 million? A billion? Maybe there is an alternate means of doing what you want to do. All in all, the conversions don't take hardly any time, and I can't think of any way right off that one could seriously optimize the process.
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC