Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3443012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:44:22+00:00 2026-05-18T08:44:22+00:00

I am trying to create a class say MyStack that would implement a java.util.collections

  • 0

I am trying to create a class say MyStack that would implement a java.util.collections class. MyStack will override some methods of the collections class like add(similar to push), remove(similar to pop) etc.. I intend to model the class on the same lines as a Set or other interfaces of the collection class except that MyStack would not be an interface or abstract class and that we can create objects of type MyStack.

I have problems with the syntax as I am not sure if I am proceeding in the right direction.All I have so far is something like this – NOTE – None of the methods have been defined so far – I am trying to get teh skeleton right before proceeding to define the methods.

import java.util.*;


public class MyStak implements java.util.Collection<E>{

    public boolean add(E o){

               return false;        
        }

       public boolean addAll(Collection c){
        return false; 

        }

       public void clear() {

       }

        public boolean contains(Object o){
          return false;

        }

        public boolean containsAll(Collection o){
          return false;

        }

        public boolean equals(Object c){
          return false; 
        }

        public int hashcode(){
          return 0; 
        }

        public boolean isEmpty(){
          return false; 
        }

        public Iterator iterator(){
          return null;

        }

        public boolean remove(Object o){
          return false; 
        }

        public boolean removeAll(Collection o){
          return false; 
        }

        public boolean retainAll(Collection o){
          return false; 
        }

        public int size(){
          return 1; 
        }

         public Object[] toArray(){
           return null;

         }

         public Object[] toArray(Object[] a){
           return null; 
         }

    }

I have a couple of compile time errors like –

    +public class MyStak implements java.util.Collection<E>{
Multiple markers at this line
    - The type MyStak must implement the inherited abstract method 
     Collection<E>.add(E)
    - E cannot be resolved to a type

    +public boolean add(E o){
Multiple markers at this line
    - E cannot be resolved to a type
    - implements 
     java.util.Collection<E>.add

Any code modifications, examples , corrections to my code , links to tutorials etc will we highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:44:23+00:00Added an answer on May 18, 2026 at 8:44 am

    Make sure to throw on a <E> specification on your class as well:

    public class MyStak<E> implements java.util.Collection<E>
                       ^^^
    

    If you want to make life easier on yourself try sub-classing AbstractCollection instead of implementing Collection directly. It provides reasonable default implementations for most of the methods to minimize the amount of code you need to write.

    java.util

    Class AbstractCollection<E>

    This class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface.

    To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the iterator and size methods. (The iterator returned by the iterator method must implement hasNext and next.)

    To implement a modifiable collection, the programmer must additionally override this class’s add method (which otherwise throws an UnsupportedOperationException), and the iterator returned by the iterator method must additionally implement its remove method.

    The programmer should generally provide a void (no argument) and Collection constructor, as per the recommendation in the Collection interface specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a C# class that can call the same methods on
I'm trying to create a LINQ to SQL class that represents the latest version
I'm trying to create a UserControl that inherits from a generic class. It does
Trying to create my first iPhone app that would play back audio. When I
I'm trying to create a collection class in Flex that is limited to housing
I'm trying to create a C++ class, with a templated superclass. The idea being,
I'm trying to create an instance of a class at run time. The classes
I'm trying to create a Quicksort base class using VB.NET, taking it an array
I currently have a class and I'm trying to create an easy GUI to
I am trying create a WCF service that leverages the WPF MediaPlayer on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.