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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:20:40+00:00 2026-05-11T01:20:40+00:00

I have the following code, which splits up a Vector into a string vector

  • 0

I have the following code, which splits up a Vector into a string vector (to use as a key) and an integer at the end (to use as value).

payoffs.put(new Vector<String>(keyAndOutput.subList(0, keyAndOutput.size() - 1)), Integer.parseInt(keyAndOutput.lastElement())); 

The TreeMap in question is constructed using a Comparator with the following method, which imposes a lexicographic, case independent ordering that also takes length into account (longer vectors are always ‘greater’ than shorter ones).

public int compare(Vector<String> arg0, Vector<String> arg1) {         int sgn = 0;         if (arg0.size() > arg1.size()) {             return 1;         } else if (arg0.size() < arg1.size()) {             return -1;         }         for (int i = 0; i < arg0.size(); i++) {             if (arg0.elementAt(i).compareToIgnoreCase(arg1.elementAt(i)) == 1) {                 sgn = 1;                 break;             } else if (arg0.elementAt(i).compareToIgnoreCase(arg1.elementAt(i)) == -1) {                 sgn = -1;                 break;             } else {                 continue;             }         }         return sgn;     } 

Now, for the problem…despite having 8 entries in the text file this is being read from, the map only ever gets up to 2 entries. Once one entry (key) is entered, it STAYS, but the VALUE changes with every iteration of the scanning process (every time it reads in a new vector from a line in the file). It throws out all the other keys except for the two.

Is this a problem with my comparator? Or is the TreeMap doing something I don’t understand with put()?

  • 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. 2026-05-11T01:20:40+00:00Added an answer on May 11, 2026 at 1:20 am

    Answering Not answering the question, with but a couple minor points besides about your code:

    1. You should not do the compareTo twice; compare once and assign the result to sgn; then break if !=0
    2. Your else continue is redundant.
    3. You should not compare for -1 or 1, but <0 or >0; many compareTo methods return based on (x1-x2), which can give any negative or positive number.

    EDIT: Doh! And, of course, the return for String.compareToIgnoreCase() is one of those (3) comparators. As the other answer posted at the same time as mine pointed out, that will likely be the cause of your error.

    EDIT2: Corrected opening statement to reflect question was actually answered.

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

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Functional Decomposition is the process of taking a complex process… May 11, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer First impressions: if( argv[i][0] = '>' ) should be: if(… May 11, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer Use the subview property of the UIView containing the buttons.… May 11, 2026 at 7:06 pm

Related Questions

This question is a result of what i noticed while trying to answer another
I'm pointing the .Net command line WSDL utility that ships with Visual Studio 2005
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.