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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:45:37+00:00 2026-06-16T19:45:37+00:00

Say I have an array of Strings like so: 0 [Some plain text] 1

  • 0

Say I have an array of Strings like so:

0 ["Some plain text"]
1 ["Foobar chicken"]

I want to search each String (in each index of the array) for a particular substring, say plain, and then return true when the first instance of the substring is found.

What’s the most effecient way to do this?

I know I can do a simple break in a for-loop but I’ve heard people say that using break in a for-loop is bad-practice. I also hear that using a while and do-while isn’t good either.

My Implementation

Here’s my simple implimentation using break:

for (String[] index : tmpList) {
    retVal = index[2].toLowerCase().contains(keyword);

    if (retVal) // Break when retVal is true
        break;
}

Where:

  • tmpList is an ArrayList<String[]>
  • keyword is what I’m trying to find
  • 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-16T19:45:38+00:00Added an answer on June 16, 2026 at 7:45 pm

    I know I can do a simple break in a for-loop but I’ve heard people say
    that using break in a for-loop is bad-practice.

    Where did you find this? That is completely wrong. Is it a bad practice to use break in a for loop?

    Just use a for loop and loop through the Strings. Use String#contains to check to see if the String has a specific substring. Then store the String in a variable (or the index if you need it) and break;.

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

Sidebar

Related Questions

Just stuck on c syntax regarding strings. Say I have a string like (
I have an array with french strings let say: égrener and exact I would
lets say we have a string[] array = {telekinesis, laureate, Allequalsfive, Indulgence}; and we
I have a string say string s =C:\\Data , I have an array which
Say I have an array of table DDL queries and I want to get
Say I have an array of arbitrary size holding single characters. I want to
Say I have an array like this: [white, red, blue, red, white, green, red,
Let's say I have this Hello.scala. object HelloWorld { def main(args: Array[String]) { println(Hello,
let's say i have a string like this: $string = 'Lorem Ipsum available, <a
I have a Web Service written in Java. I want to send some strings

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.