Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: stack implementation

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default stack implementation

    hello evryone!!!!
    if u asked to implement a stack using an ArrayList given the the stack interface,do i have to create a stack class that extends arraylist after i create the one that implements stack interface....?
    May some one briefly explain wat implementing stack using a arraylist mean.?do they mean stack inherits arraylist properties or wat?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: stack implementation

    I'm hesitant to say that extending ArrayList as ArrayListStack is the correct solution here because this would allow more access than a true Stack should allow. This isn't necessarily a bad thing, but you need more solid specifications before a good recommendation can be made.

    In general, I would prefer a composition solution. Your stack implementation class would use an ArrayList internally for storing the stack state, but it would not be an ArrayList because an ArrayList provides RandomAccess which a stack shouldn't have.

Similar Threads

  1. what is difference between call stack and stack tace?
    By me_shankara in forum Exceptions
    Replies: 6
    Last Post: October 27th, 2018, 03:23 AM
  2. Stack implementation and shallow copy
    By Shaybay92 in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 20th, 2012, 12:32 AM
  3. Stack implementation with given condition
    By Magesh in forum Member Introductions
    Replies: 2
    Last Post: August 31st, 2011, 01:17 AM
  4. Implementation Stack Using Array
    By rainbow9 in forum Java Programming Tutorials
    Replies: 1
    Last Post: August 20th, 2011, 09:48 AM
  5. stack
    By ridg18 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 22nd, 2011, 12:45 PM