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 6804461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:28:06+00:00 2026-05-26T19:28:06+00:00

I need to implement a bag data structure using the interface java.util.Collection . I’m

  • 0

I need to implement a bag data structure using the interface java.util.Collection.
I’m not asking for help on the actual implementation of the data structure. I just can’t get my program to compile. I just want to get a blank implementation of the interface (with non functional signatures of the methods) to compile before I start actually implementing methods.

class Bag<T> implements java.util.Collection<T> 
  {

  public void Collection () {

  }

  public boolean add(E e) {

  }

  public boolean addAll (Collection<? extends E> c) {

  }

  public void clear() {

  }

  public boolean contains(Object o) {

  }

  public boolean containsAll(Collection<?> c) {

  }

  public boolean equals(Object o) {

  }

  public int hashCode() {

  }

  public boolean isEmpty() {

  }

  public Interator<E> interator() {

  }

  public boolean remove(Object o) {

  }

  public boolean removeAll(Collection<?> c) {

  }

  public int size() {

  }

  public Object[] toArray() {

  }

  public <T> T[] toArray(T[] a) {

  }
}

Compiler can’t find class E in the parameters of methods like add. Am I supposed to define a class for E, or is there something I’m not understanding about what E actually is? Compiler says it can’t find class Collection (in the parameters of methods like addAll) Do I import java.util.Collection or is there something else I should know? Compiler also has no idea about class Iterator and neither do I.

I know this is all probably elementary, but I could not find anything via Google, etc yesterday and my professor’s lectures don’t follow the projects at all. I’m lost on this one. Thanks for any help!

Edit: Also, I haven’t searched as much on this but if someone could tell me anything useful about the “?”s such as public boolean addAll (Collection<? extends E> c) {}, that would be greatly 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-26T19:28:07+00:00Added an answer on May 26, 2026 at 7:28 pm

    Either use T or E as the type parameter, and then use it consistently throughout your class definition.

    The Java documentation uses E, so you could for example change the first line to:

    class Bag<E> implements java.util.Collection<E> 
    

    You will also need to either return values or throw an exception for those methods that don’t return void.

    public int size() {
        throw UnsupportedOperationException();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to have a type-safe bag of items that all implement a generic interface.
I'm supposed to implement a bag data structure (also called a multiset), an unordered
I need to implement RSA algorithm in Java. I've found the best solution using
need to implement a global error handling, so maybe you can help out with
Hi I need implement context help inside my .NET application. I have .chm file
I need implement a Data entry like receiver field in mail app (Ex. To:
I need to implement an n:m relation in Java. The use case is a
I need to implement the website visitor count Usercontrol.Can any one help me regarding
I need to implement an application that is simultaneously communicating with multiple clients using
I need to implement a Diff algorithm in VB.NET to find the changes between

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.