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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:57:56+00:00 2026-05-28T02:57:56+00:00

I have a string which may or may not end with whitespace and I’m

  • 0

I have a string which may or may not end with whitespace and I’m having trouble determining whether that’s the case.

The reason why I am asking this is because I need a good way to calculate the width of the android since my string auto corrects and goes to the next line.

In android it looks like something like this:

 The quick brown fox jumps over the lazy dog

 The quick brown fox jumps over the lazy d - my method substrings the data to fit on screen.

|The quick brown fox jumps over the lazy  | - this is how it would look like on android

|dog---------------(empty space)----------|

Now to rephrase my question I want to know what method do I need to use to check the last character in my string is whitespace?

  • 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-28T02:57:56+00:00Added an answer on May 28, 2026 at 2:57 am

    In short:

    boolean isSpace = yourString.charAt(yourString.length() – 1) == ‘ ‘;

    EDIT:
    After reading the great comment from MH bellow, you should instead use:

    boolean isSpace = Character.isWhitespace(yourString.charAt(yourString.length() - 1));
    

    But if you want only to remove the space at the end, you can use the trim() method on the String class:

    yourString = yourString.trim();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that contains string which may contain whitespaces appended to the
I have a string which may contain cell address, which is look like: A1,
I'm using .NET 3.5. I have two string arrays, which may share one or
I have the string which that encoded in quoted-printable . How do I decode
I have some code validating a string of 1 to 32 characters, which may
I have to work with strings which may contain Lat/Long data, like this: $query
I have a simple list of strings, which may be of arbitrary length. I'd
I have a string which is like this: this is "a test" I'm trying
I have a string which contain tags in the form < tag > .
I have a string which starts with //#... goes upto the newline characater. I

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.