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

  • Home
  • SEARCH
  • 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 3848302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:40:54+00:00 2026-05-19T16:40:54+00:00

Which class would work best for a non-ordered list of pairs? I’ll be taking

  • 0

Which class would work best for a non-ordered list of pairs? I’ll be taking a bunch of (float,short) pairs and will need to be able to perform simple math (like multiplying the pair together to return a single float, etc). List only takes one argument, and HashMap won’t allow duplicates (as far as I know). Any thoughts?

  • 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-19T16:40:54+00:00Added an answer on May 19, 2026 at 4:40 pm

    You can use the Entry<U,V> class that HashMap uses but you’ll be stuck with its semantics of getKey and getValue:

    List<Entry<Float,Short>> pairList = //...
    

    My preference would be to create your own simple Pair class:

    public class Pair<L,R> {
        private L l;
        private R r;
        public Pair(L l, R r){
            this.l = l;
            this.r = r;
        }
        public L getL(){ return l; }
        public R getR(){ return r; }
        public void setL(L l){ this.l = l; }
        public void setR(R r){ this.r = r; }
    }
    

    Then of course make a List using this new class, e.g.:

    List<Pair<Float,Short>> pairList = new ArrayList<Pair<Float,Short>>();
    

    You can also always make a Lists of Lists, but it becomes difficult to enforce sizing (that you have only pairs) and you would be required, as with arrays, to have consistent typing.

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

Sidebar

Related Questions

I have a class which would create a bean and the bean has few
I want to implement a generic method on a generic class which would allow
I would like to add a class which renders an element a particular color
I have a class which is intended for immutable use, hence I would like
I would like to create a JTable like the below picture: Which java class
I have a public static class in which I would like to have a
I would like make an extension method for the generic class A which takes
I'm writing a simple C++ class in which I would like cache picture thumbnails
I have some classes(call it Class A) which I would like to unit test
I want to have a string variable for a PHP class, which would be

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.