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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:24:12+00:00 2026-06-12T14:24:12+00:00

I trying to compare 2 strings in Java to determine if they are the

  • 0

I trying to compare 2 strings in Java to determine if they are the same:

System.out.println("app version: "+ appversion + " latest version: "+ latestversion); 

if(!appversion.equals(latestversion))
{            
    System.out.println("not the same"); 
}

However this is giving me unexpected results given the outputs:

app version: v1.1.2 latest version: v1.1.2
not the same

I have used .replaceAll("\\s",""); to remove any whitespaces from the strings with no success.

There is probably a very obvious answer to this but can anyone tell me what i’m doing wrong?

  • 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-12T14:24:13+00:00Added an answer on June 12, 2026 at 2:24 pm

    Instead of .replaceAll() method, use trim() method to remove white space while comparing String variables.

    change your code as follows as,

    if(!appversion.trim().equals(latestversion.trim()))
    {            
        System.out.println("not the same"); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I compare strings in Java? I am trying to compare
I am trying to compare two strings in a simple shell script. I was
I am trying to compare two strings in Smalltalk, but I seem to be
I'm trying to compare two strings. One stored in a file, the other retrieved
I am trying to compare two strings I get from a password form in
I am trying to compare two variables in which are usually strings. These variables
I am trying to compare 2 columns for similarities. There are strings in columns
I am trying to write a method that uses recursion to compare the strings
I'm trying to compare passwords in java coming from a web service. I invoke
I am trying to compare strings in bash. I already found an answer on

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.