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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:32:26+00:00 2026-05-13T05:32:26+00:00

I am studying Data Structures in java and I am having difficulty with using

  • 0

I am studying Data Structures in java and I am having difficulty with using generics in Binary Search Trees.

For our assignment we are to implement a Binary Search Tree using nodes that contain a parent, left and right node as well as a data value.

The data value in our case takes the form of a Pair object. This is what it looks like:

public class Pair<A,B> {

    public final A fst;
    public final B snd;

    public Pair(A x, B y) {
        fst = x;  snd = y;
    }

    public String toString() {
      return new String("("+fst.toString()+", "+snd.toString()+")");
    }
}

Pair is associtated with two different generics with the first part being the Key and the second being the Value associated with that key.

I also need to implement Iterator in my BST class. I am implementing the Iterator in an inner class that looks something like this:

public Iterator<Pair<K,T>> iterator() {
    return new BSTMapIter<Pair<K,T>>(this.root, this.size, this.order);
}

private class BSTMapIter<Pair<K,T>> implements Iterator<Pair<K,T>> { <=== Compiler error "> expected"
    ...
    ... (Implementation here)
    ...
}

The problem I am running into is a compiler error saying “> expected” which leads to other compiler errors (“<identifier expected>” etc.). From my understanding it is choking over <Pair<K,T>> but I have no idea why. I am assuming it is a mistake I made with using generics somewhere, but I am not entirely sure where to look.

I apologize if what I have provided is too vague but I have not encountered any problems with Pair in my implementation anywhere else but here in the implementation of the Iterator.

Can anyone tell me what I am doing wrong here???
If any further information is needed, let me know and I will do my best to provide 🙂

  • 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-13T05:32:26+00:00Added an answer on May 13, 2026 at 5:32 am

    The problem is the way you’re trying to make BSTMapIter generic. It needs to be generic in two type parameters, K and T. The Pair part is irrelevant at this point. (It’s important when it comes to what interface it implements though.) So the declaration should be:

    private class BSTMapIter<K,T> implements Iterator<Pair<K,T>>
    

    However, that’s if you want BSTMapIter to be generic in itself. If this is a nested class within a type which already has K and T as type parameters, you probably just want:

    private class BSTMapIter implements Iterator<Pair<K,T>>
    

    You also want to instantiate it slightly differently:

    // When it's an inner class
    public Iterator<Pair<K,T>> iterator() {
        return new BSTMapIter(this.root, this.size, this.order);
    }
    
    // When it's a standalone generic class
    public Iterator<Pair<K,T>> iterator() {
        return new BSTMapIter<K, T>(this.root, this.size, this.order);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying the best data structures to implement a simple open-source object temporal database,
I'm studying data structures (List, Stack, Queue), and this part of code is confusing
I've been studying my fundamental data structures a bunch recently, trying to make sure
I'm now studying Fundamentals Of Data Structures in C++ written by Ellis Horowitz ,
I have started studying data structures again . I found very few practical uses
I'm studying data structures and linked lists, but I'm not getting the concept of
I'm studying using Core Data. After I create the entity in Xcode, I want
I'm planning to invest some time every week studying data structures and algorithms. Do
I'm studying up on archiving data, and I realize the standard collection classes provide
i'm studying getPixel32() and the Bitmap and Bitmap Data classes. Basically, i'd like to

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.