• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I missed the Campbell's answer.
thanks.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand, thanks a lot Rob.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic