I have code like as String[] parts=str.split(":") I want to confirm if parts[] array dont have any empty or null string. What is optimal way to do this ?
            Asked
            
        
        
            Active
            
        
            Viewed 133 times
        
    -5
            
            
         
    
    
        Vaibhav R
        
- 13
- 3
- 
                    You won't have `null` element but you can have empty ones like if sentence if `Hey :: man :` – azro Mar 31 '21 at 17:38
- 
                    Does this answer your question? [Check whether a string is not null and not empty](https://stackoverflow.com/questions/3598770/check-whether-a-string-is-not-null-and-not-empty) – azurefrog Mar 31 '21 at 17:39
1 Answers
0
            Just a foreach loop on the array
static boolean hasEmpty(String[] values){
    for(String elt : values)
        if(elt.isEmpty())
            return true;
    return false;
}
If you want to add a not only whitespace string use
if (elt.isEmpty() || elt.isBlank()) {
 
    
    
        azro
        
- 53,056
- 7
- 34
- 70