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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:39:14+00:00 2026-05-24T01:39:14+00:00

I created a Color Chooser with three textboxes where the user defines rgb values.

  • 0

I created a “Color Chooser” with three textboxes where the user defines rgb values.
To check if values entered are correct (only numbers between 0-255) I’m using the following:

public Color getColor() {
    if (tfRed.getText().equals("") || tfGreen.getText().equals("") || tfBlue.getText().equals("")) {
                return new Color(0, 0, 0, 0);
    } else {
        if (tfRed.getText().matches("\\d+") && tfGreen.getText().matches("\\d+") && tfBlue.getText().matches("\\d+")) {
            // ...
        } else {
            return new Color(0, 0, 0, 0);
        }
    }
}

What I’m asking: is it better to use String.isEmpty()? I never found a satisfying answer and I’ve always wondered if there is any difference.

  • 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-24T01:39:16+00:00Added an answer on May 24, 2026 at 1:39 am

    I think isEmpty() is a bit more efficient. However a smart compiler may optimize the equals("") call anyway. From the OpenJDK source:

      671     public boolean isEmpty() {
      672         return count == 0;
      673     }
    
     1013     public boolean equals(Object anObject) {
     1014         if (this == anObject) {
     1015             return true;
     1016         }
     1017         if (anObject instanceof String) {
     1018             String anotherString = (String)anObject;
     1019             int n = count;
     1020             if (n == anotherString.count) {
     1021                 char v1[] = value;
     1022                 char v2[] = anotherString.value;
     1023                 int i = offset;
     1024                 int j = anotherString.offset;
     1025                 while (n-- != 0) {
     1026                     if (v1[i++] != v2[j++])
     1027                         return false;
     1028                 }
     1029                 return true;
     1030             }
     1031         }
     1032         return false;
     1033     }
    

    Also the answer here on whether to use str.isEmpty() or "".equals(str) is spot on:

    The main benefit of "".equals(s) is you don’t need the null check (equals will check its argument and return false if it’s null), which you seem to not care about. If you’re not worried about s being null (or are otherwise checking for it), I would definitely use s.isEmpty(); it shows exactly what you’re checking, you care whether or not s is empty, not whether it equals the empty string

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

Sidebar

Related Questions

I created a tree but i'm unaware of setting color to it. JTree tree;
I have created a new attribute Catalog -> Attributes -> Manage Attributes COLOR in
In my constructor, I want to create a random color. Therefore, I need three
I've been assigned to set color temperature to a value between 1000 and 10.000
What I need is a simple color picker (max 6-8 color) so the user
I have created custom View called Color . I use object of Color to
I have a data set that resembles this: id product_id size color price created_date
I've created a cookie like below and can retrieve all font_size , back_color and
I need to create a color animation. I have a control (a slick button
I've been trying to create a color LinearLayout object (1) within another LinearLayout object

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.