How to extract only words with first-letter lowercase from a string in Java

4 Answers

0 votes
class Program {
    public static void main(String[] args) {
        String s = "java Programming language"; 
        String lcw = "";        
        String[] arr = s.split(" ");    
  
        for (String word : arr) {
            if (Character.isLowerCase(word.charAt(0))) {
                lcw += word + " ";
            }
        }
                 
        lcw = lcw.trim();
        
        System.out.println(lcw);
    }
}



/*
  
run:
                     
java language
   
*/

 



answered Feb 5, 2017 by avibootz
edited Apr 13, 2024 by avibootz
0 votes
class Program {
    public static void main(String[] args) {
        String s = "java Programming language"; 
        
        String[] arr = s.split(" ");    
   
        for (String word : arr) {
            if (Character.isLowerCase(word.charAt(0))) {
                System.out.println(word);
            }
        }
    }
}



/*
  
run:
                     
java
language
   
*/

 



answered Feb 5, 2017 by avibootz
edited Apr 13, 2024 by avibootz
0 votes
import java.util.ArrayList;
  
class program {
    static ArrayList<String> extract_only_words_with_first_letter_lowercase(String s) {
        ArrayList<String> words = new ArrayList<String>();
 
        int start = 0;
        int end;
        while ((end = s.indexOf(" ", start)) != -1) {
            String word = s.substring(start, end);
  
            if (Character.isLowerCase(word.charAt(0))) {
                words.add(word);
            }
            start = end + 1;
        }
      
        if (Character.isLowerCase(s.substring(start).charAt(0))) {
            words.add(s.substring(start));
        }
      
        return new ArrayList<String>(words);
    }
      
    public static void main(String[] args) {
        String s = "Java is a High-level, object-oriented pPogramming language";
      
        ArrayList<String> words = extract_only_words_with_first_letter_lowercase(s);
      
        for (String w : words) {
            System.out.println(w);
        }
    }
}
  
  
  
  
/*
run:
    
is
a
object-oriented
pPogramming
language
    
*/

 



answered Apr 13, 2024 by avibootz
0 votes
import java.util.ArrayList;
  
class program {
    static ArrayList<String> extract_only_words_with_first_letter_lowercase(String s) {
        ArrayList<String> lowercase = new ArrayList<String>();
        String[] words = s.split("\\s+");
  
        for (String word : words) {
            if (Character.isLowerCase(word.charAt(0))) {
                lowercase.add(word);
            }
        }
         
        return new ArrayList<String>(lowercase);
    }
      
    public static void main(String[] args) {
        String s = "Java is a High-level, object-oriented pPogramming language";
      
        ArrayList<String> words = extract_only_words_with_first_letter_lowercase(s);
      
        for (String w : words) {
            System.out.println(w);
        }
    }
}
 
  
  
/*
run:
    
is
a
object-oriented
pPogramming
language
    
*/

 



answered Apr 13, 2024 by avibootz
...