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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:23:08+00:00 2026-06-12T17:23:08+00:00

I have a requirement in which I need to remove the semicolon if it

  • 0

I have a requirement in which I need to remove the semicolon if it is present at the end of the String(only at the end). I have tried the following code. But still it is not getting replaced. Can anyone please tell what I need to change in the following code in the line number
(I referred the code from here How do I delete specific characters from a particular String in Java?)

public static void main(String[] args) {
    String text = "wherabouts;";
    System.out.println("SSS "+text.substring(text.length()-1));
    if(text.substring(text.length()-1) == ";"){
        text.replaceAll(";", "");
    }
    System.out.println("TEXT : "+text);
}
  • 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-12T17:23:09+00:00Added an answer on June 12, 2026 at 5:23 pm
    text.replaceAll(";", "");
    

    Since Strings in Java are immutable, so replaceALl() method doesn’t do the in-place replacement, rather it returns a new modified string. So, you need to store the return value in some other string. Also, to match the semi-colon at the end, you need to use $ quantifier after ;

    text = text.replaceAll(";$", "");
    

    $ denotes the end of the string since you want to replace the last semi-colon..

    If you don’t use $, it will replace all the ; from your strings..

    Or, for your job, you can simply use this, if you want to remove the last ;:

        if (text.endsWith(";")) {
            text = text.substring(0, text.length() - 1);
            System.out.println(text);
        }
    

    UPDATE: And, if there are more semi-colons at the end:

    text = text.replaceAll(";+$", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have a requirement which i need to include a layout (actually
I have a unique requirement which I need to meet to with sitecore, and
I have a requirement which sounds like kind of simple but hard to implement
I have a requirement where the interface, which contains a video, is portrait only
i have a requirement, where i need to develop a single method which accepts
Using .NET, I have a requirement in which I need to execute a process
I'm using acts_as_taggable_on, but now have a new requirement: The end goal: Users should
I have a weird requirement which I need to use inside my Stored Procedure
I have a data storage requirement which is an excellent candidate for single instance
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field

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.