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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:14:37+00:00 2026-06-12T23:14:37+00:00

I would like to find an efficient way (not scanning the String 10,000 times,

  • 0

I would like to find an efficient way (not scanning the String 10,000 times, or creating lots of intermediary Strings for holding temporary results, or string bashing, etc.) to write a method that accepts a String and determine if it meets the following criteria:

  • It is at least 2 characters in length
  • The first character is uppercased
  • The remaining substring after the first character contains at least 1 lowercased character

Here’s my attempt so far:

private boolean isInProperForm(final String token) {
    if(token.length() < 2)
        return false;

    char firstChar = token.charAt(0);
    String restOfToken = token.substring(1);
    String firstCharAsString = firstChar + "";
    String firstCharStrToUpper = firstCharAsString.toUpperCase();

    // TODO: Giving up because this already seems way too complicated/inefficient.
    // Ignore the '&& true' clause - left it there as a placeholder so it wouldn't  give a compile error.
    if(firstCharStrToUpper.equals(firstCharAsString) && true)
        return true;

    // Presume false if we get here.
    return false;
}

But as you can see I already have 1 char and 3 temp strings, and something just doesn’t feel right. There’s got to be a better way to write this. It’s important because this method is going to get called thousands and thousands of times (for each tokenized word in a text document). So it really really needs to be efficient.

Thanks in advance!

  • 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-12T23:14:38+00:00Added an answer on June 12, 2026 at 11:14 pm

    This function should cover it. Each char is examined only once and no objects are created.

    public static boolean validate(String token) {
      if (token == null || token.length() < 2) return false;
      if (!Character.isUpperCase(token.charAt(0)) return false;
      for (int i = 1; i < token.length(); i++)
        if (Character.isLowerCase(token.charAt(i)) return true;
      return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there's an efficient algorithm to find the greatest
I would like to find a way to store multiple addresses for one subject
I would like to find a way to see what happens while my XAML
I would like to find a way to compile and package our iPhone application
I would like to find the files containing specific string under linux. I tried
Would the most efficient way-and I know it's not very efficient, but I honestly
I am implementing a loaner system and would like find out the most efficient
I would like to find the distance of every pixel coordinate in an image
I would like to find out which version of an executable the CMD shell
I would like to find out is as3 is doing is doing anything in

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.