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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:30:39+00:00 2026-06-06T14:30:39+00:00

I have this methods getParam public int getParam(String paramName){ if(paramName.equals(Balls and net)){ expressionParam=1; }

  • 0

I have this methods

getParam

public int getParam(String paramName){

    if(paramName.equals("Balls and net")){
        expressionParam=1;
    }
    else if(paramName.equals("Balls and bat")){
        expressionParam=2;
    }
    else if(paramName.equals("Without balls")){
        expressionParam=3;
    }
    else if(paramName.equals("Team Sport")){
        expressionParam=4;
    }
    else{
        expressionParam=-1;
    }

    return expressionParam;
}

but for some strange reason the equals in the if conditions returns always false and the method consequentially returns always -1

I invoke this method in the follow button listener

JButton btnNewButton = new JButton("    OK   ");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    Object[][] matrix=(((MyTableModel) table.getModel()).getDatamatrix());
                     List<Expression> list=new LinkedList<Expression>(); 
                     for (int i = 0; i <elem; i++){
                         Expression e=new Expression(getSport((matrix[i][0]).toString()), getParam((matrix[i][1]).toString()), getSport((matrix[i][2]).toString()));
                         list.add(v); 


             }catch...

and with a println I have verified that the values passed to getParams match.

So what is wrong with this method??

  • 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-06-06T14:30:40+00:00Added an answer on June 6, 2026 at 2:30 pm

    Most likely you have trailing or leading whitespaces. trim() first:

    public int getParam(String rawParamName){
      final String paramName = rawParamName.trim();
    
      if(paramName.equalsIgnoreCase("Balls and net")){
      //...
    

    Also watch out for character case. Team sport will actually return -1. Consider usingequalsIgnoreCase() instead.

    Finally you might have different number or type of white spaces, e.g. two spaces or tab between character. This requires a little bit more work.

    Finally if you want to be extra flexible consider using levenshtein distance.

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

Sidebar

Related Questions

how exactly I can use public methods (non-virtual) with NHibernate? I have this code:
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I have this method to display the contact numbers in my inbox: public ArrayList<String>
I have written this class-methods for .net 2.0 to create objects from '|'-separated strings
I have this class public class Overloaded { public void ComplexOverloadResolution(params string[] something) {
I have methods in all of my models that look like this: def formatted_start_date
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that
I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden
I have a class defined like this, with the appropriate getter and setter methods...

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.