- 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
Check if a String starts with any of the given prefixes in Java
Let’s say the string is −
String str = "Malyalam";
Let’s say the prefixes are in an array −
String[] prefixArr = { "Ga", "Ma", "yalam" };
Now, to check whether the string starts with any of the abive prefix, use the startsWith() −
if (Stream.of(prefixArr) .anyMatch(str::startsWith)) System.out.println("TRUE"); else System.out.println("FALSE");
Following is an example to check is a string starts with any of the given prefixes −
Example
import java.util.stream.Stream; class Main { public static void main(String[] args) { String str = "Malyalam"; String[] prefixArr = { "Ga", "Ma", "yalam" }; if (Stream.of(prefixArr) .anyMatch(str::startsWith)) System.out.println("TRUE"); else System.out.println("FALSE"); } }
Output
TRUE
- Related Articles
- Java Program to check if any String in the list starts with a letter
- Check if a string starts with given word in PHP
- Python Check if suffix matches with any string in given list?
- How to check if a string starts with a specified Prefix string in Golang?
- How to check if string or a substring of string starts with substring in Python?
- Java Program to check if the String contains any character in the given set of characters
- Find if a string starts and ends with another given string in C++
- Python Program to check if a string starts with a substring using regex
- Count all prefixes in given string with greatest frequency using Python
- Java program to check if a string contains any special character
- Check if a string ends with given word in PHP
- How to check whether a string starts with XYZ in Python?
- Check if the Slice of bytes starts with specified prefix in Golang
- Golang Program to check a string starts with a specified substring
- Swift Program to check a string starts with a specified substring

Advertisements