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

  • Home
  • SEARCH
  • 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 9169539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:35+00:00 2026-06-17T15:53:35+00:00

To make things simple, I have an ArrayList called items (which stores a string

  • 0

To make things simple, I have an ArrayList called “items” (which stores a string the user inputs) and this bit of code:

int index = items.lastIndexOf("i am");
if (index >= 0)
System.out.println("yay");

When I test it out, if I type in “i am” at the beginning it outputs “yay” like it should. But, if I type in something like “yes i am” it doesn’t output anything. Is there a way I can have it so “yay” is displayed if I type in something like “yes i am” or am I restricted to having it just at the beginning?

Here’s how I setup the ArrayList:

List<String> items = Arrays.asList(user.split("\\s*,\\s*"));

Thanks.

  • 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-17T15:53:36+00:00Added an answer on June 17, 2026 at 3:53 pm

    It seems to me you are splitting the input string on a comma (in an awkward way too). Since yes I am doesn’t contain a comma, your array will only have a single element: ["yes I am"]. Which means that lastIndexOf("i am") will not match. Hence you aren’t seeing yay being printed out.

    Now, to the matter of how to make this work.

    1. Type in yes, i am
    2. as someone suggested
      in the comment, match on the original input string with
      user.indexof("i am").

    Basically, it’s hard to recommend a solution because I don’t know what your ultimate goal is.

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

Sidebar

Related Questions

My boss believes that wizards make things simple for the user. I think they
To make things simple, my Delphi XE application contains objects in charge of generating
EDIT: Just to make things clear, this problem was caused by a typo in
I have a wordpress theme that I like to duplicate. To make things easier
I'm trying to make a function that does different things when called on different
Make things as simple as possible, but no simpler. Can we find the solution/s
Things are simple, I want to make a widget with 4 lines and 4
I have a very simple Java JTable question. I am creating this class to
Doctrine 2 integration into ZF seems to make simple things very hard and time
I have this piece of code that basically checks if one or more files

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.