wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes the world�s worst attempt at making  ArrayList kind of class, from scratch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the world�s worst attempt at making  ArrayList kind of class, from scratch" Watch "the world�s worst attempt at making  ArrayList kind of class, from scratch" New topic
Author

the world�s worst attempt at making ArrayList kind of class, from scratch

frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
Hi, there is the following class in the book HeadFirstJava. Please see the code comment.
How would look a good one?
Thank you.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
You need an "else" which enlarges the array. The System#arraycopy method might be the quickest way to do that.
Then you add in a similar manner to before.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

java.util.ArrayList would also be a good idea, unless it is a homework exercise.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
Rob, you may not have read the the comment:
Perhaps the world�s worst attempt at making our
own ArrayList kind of class, from scratch.


I would like to know why the attempt is perhaps the worst.

Thanks.
frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
the book is full of jokes, it may be one of them
frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
Sorry, I missed the Campbell's answer.
thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Originally posted by frantisek nejedly:
Rob, you may not have read the the comment:


I would like to know why the attempt is perhaps the worst.

Thanks.

It is bad because it does not allow for any growth. 5 elements, and that's it. There is also no way of removing or retrieving anything.


Also, you asked "How would look a good one?". My answer to that was: java.util.ArrayList.
frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
I understand, thanks a lot Rob.
George McCready
Greenhorn

Joined: Feb 05, 2007
Posts: 2
Originally posted by frantisek nejedly:
the book is full of jokes, it may be one of them


It's also full of errors. Check the online errata for the book
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

"george mc", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
frantisek nejedly
Ranch Hand

Joined: Sep 09, 2008
Posts: 42
I've just checked the errata for the book, you're right. Thanks.
George McCready
Greenhorn

Joined: Feb 05, 2007
Posts: 2
Originally posted by Bear Bibeault:
"george mc", please check your private messages for an important administrative matter.


Done. Screen name doesn't seem to retroactively update, though. Is that normal?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by George McCready:
Done. Screen name doesn't seem to retroactively update, though. Is that normal?
Yes, sort of. They get updated eventually where they are treated as screen names, but not when they're pasted into posts as text.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the world�s worst attempt at making ArrayList kind of class, from scratch
 
Similar Threads
public and private inheritance in Java like in C++?
Head First Java problem
K&B SCJP5 pg 574 - Generics
Whats wrong with this code
Chapter 7 - Objective 6.3 & 6.4 - type parameter for method checkAnimals () method.