• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
frantisek nejedly
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.ArrayList would also be a good idea, unless it is a homework exercise.
 
frantisek nejedly
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the book is full of jokes, it may be one of them
 
frantisek nejedly
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I missed the Campbell's answer.
thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand, thanks a lot Rob.
 
George McCready
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"george mc", please check your private messages for an important administrative matter.
 
frantisek nejedly
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just checked the errata for the book, you're right. Thanks.
 
George McCready
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic