Is the String isEmpty method really inaccessible at API level API <10?

I also use NetBeans nbandroidto create my Android application. I used to focus on API level 10 (2.3.3), but I realized that I excluded too many people from my application, and (I thought) my application did not use any functions that exceeded API level 7. However, after changing my API level in the project properties in NetBeans, my project will not compile or compile the condition myString.isEmpty(). I know this is easy to fix / replace, but String.isEmptyreally not available until API level 10? If not, how can I fix my project nbandroid? I noticed that even after I select the API level in the project properties, under the libraries it always says Android 2.3.3.

+3
source share
5 answers

Perhaps you are still saying that you are using the 2.3.3 library as you have targetSdkit installed in 2.3.3.


With a minimum SDK of over 2.2 (8) you will lose 27.1% of the audience

With a minimum SDK with over 2.1 (7) you will lose 6.2%

With a minimum SDK of more than 1.6 (6) you will lose 0.7%

so this is for you if you do not want to aim at 2.3 (9) .

(I personally would recommend having your minSdk as 2.2 (8) and targeting 3.0 (11))


Like for String.isEmpty ()

 if("".equals(String)){
   // is Empty
 }

or

 if(!"".equals(String) && String != null){
   // is Not Empty
 }

For a complete implementation of isEmpty, you need to remember that your line may be empty or full of spaces (which is technically empty):

 if(String != null && "".equals(String.trim())){
   // is Empty
 }

null trim() NullPointerException

Ref:

+2

, ( isEmpty), , , 0 equals, :

if ( myString.length() == 0 )
{
  // is emtpy
}

, , isEmpty .

+4

isEmpty API 9. (Reference)

API 7, , String.length() != 0, isEmpty();

+3

. API 9 . , .

+2

, .

+1

All Articles