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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:24:19+00:00 2026-05-24T13:24:19+00:00

So in Java, I know that str.endsWith(suffix) tests if str ends with something. Let’s

  • 0

So in Java, I know that str.endsWith(suffix) tests if str ends with something. Let’s say I have a text with the line “You are old” in it. How would I take the “old” and set it as a variable so I can print it out in the console?

I know I could do:

if(str.endsWith("old")){ 
   String age = "old";
}

But then I’m going to have more options, so then I’d have to do:

if(str.endsWith("option1")){ 
   String age = "option1";
}

if(str.endsWith("option2")){ 
   String age = "option2";
}

...

Is there a more efficient and less verbose way to check the end of strings over writing many, possibly hundreds, of if statements

Format:
    setting: option
    setting2: option2
    setting3: option3 ...

Regardless of what “option” is, I want to set it to a variable.

  • 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-24T13:24:20+00:00Added an answer on May 24, 2026 at 1:24 pm

    If you are working with sentences and you want to get the word, do

    String word = str.substring(str.lastIndexOf(" "));
    

    You may need a +1 after the lastIndexOf() to leave the space out.
    Is that what you are looking for?

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

Sidebar

Related Questions

I know that Open Office Database uses a java database backend. Does anyone have
I have an exe that I know was written in java. I understand that
In Java, I know that the default thread priority is 5. I have a
I know that you can run almost all Java in Dalvik's VM that you
i know that the JDK consists of all java packages .But what does the
I know that Serialization (Serializable) is not available in the Micro Edition of Java.
Does anyone know a good Java lib that will hook into SVN so I
Does anyone know of a Java library that handles finding sentence boundaries? I'm thinking
Do you know any libraries similar to java.util.Properties that support more advanced features like
Anyone know if it is possible to write an app that uses the Java

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.