- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to check if any String in the list starts with a letter
First, create a List with String elements:
List<String> myList = new ArrayList<>(); myList.add("pqr"); myList.add("stu"); myList.add("vwx"); myList.add("yza"); myList.add("bcd"); myList.add("efg"); myList.add("vwxy");
Use the startsWith() method to check if any of the above string in the myList begins with a specific letter:
myList.stream().anyMatch((a) -> a.startsWith("v"));
TRUE is returned if any of the string begins with the specific letter, else FALSE.
The following is an example to check if any String in the list starts with a letter:
Example
import java.util.ArrayList; import java.util.List; public class Demo { public static void main(final String[] args) { List<String> myList = new ArrayList<>(); myList.add("pqr"); myList.add("stu"); myList.add("vwx"); myList.add("yza"); myList.add("bcd"); myList.add("efg"); myList.add("vwxy"); boolean res = myList.stream().anyMatch((a) -> a.startsWith("v")); System.out.println("Do any string begins with letter v = "+res); } }
Output
Do any string begins with letter v = true
- Related Articles
- Check if a String starts with any of the given prefixes in Java
- Python Program to check if a string starts with a substring using regex
- Java program to check if a string contains any special character
- How to check if a string starts with a specified Prefix string in Golang?
- Check if a string starts with given word in PHP
- Python Check if suffix matches with any string in given list?
- Golang Program to check a string starts with a specified substring
- Swift Program to check a string starts with a specified substring
- How can I test if a string starts with a capital letter using Python?
- How to check if string or a substring of string starts with substring in Python?
- Java Program to check if none of the string in the list matches the condition
- Java Program to check if the String contains any character in the given set of characters
- Program to check if a string contains any special character in C
- Program to check if a string contains any special character in Python
- C# program to check if a string contains any special character

Advertisements