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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:30:15+00:00 2026-05-25T23:30:15+00:00

I created a method to basically detect white space characters. I go through a

  • 0

I created a method to basically detect white space characters. I go through a string and check each character for white space. If it is a white space character, I return true, and if it’s not, I return false. However, I get a compilation error, stating “missing return statement”. As I already have two return statements “true” and “false”, I can’t see why there is an error. Can you help me out or point me in the right direction? Thanks in advance.

public boolean isWhitespace()
{
    for (int i=0; i<string.length(); i++)
    {
        if (Character.isWhitespace(i))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
  • 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-25T23:30:16+00:00Added an answer on May 25, 2026 at 11:30 pm

    You are looping over the length of the String, yet trying to return inside that loop. The logic doesn’t make sense.

    Think about the problem you are trying to solve – do you want to test if a character is a whitespace, or if an entire String contains at least one whitespace character? For the latter:

    boolean hasWhite = false;
    for(int i=0; i < string.length(); i++)
    {
      if(Character.isWhitespace(string.charAt(i)))
      {
         hasWhite = true;
         break;
      }
    }
    
    return hasWhite;
    

    EDIT: A much simpler approach, if you’re into that sorta thing 😉 –

    return string.contains(" ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a method like NUnit's Throws method. Basically, the method should return
I am using the following method to basically create a JSON string. var saveData
I have created a method to check if the keyboard is used in an
I created the following method for retrieving stored settings from the database: public String
Basically I wan't to obtain a string from the user, I have created a
I have a method CreateAccount(...) that I want to unit test. Basically it creates
I created a method to unmarshall my xml (item.xml) file .But if there are
I created a method to swap the cars from the owners. bool owner::changeCar(owner& other,
I've created a method using the new WebAPI features in MVC4 and have it
I have created a method that should ideally take a single Account object and

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.