The Java program you provided checks if all strings in a list start with the letter 'S' (uppercase) or 's' (lowercase) using Java Streams and the allMatch method. Here's an explanation of the code:
import java.util.ArrayList; import java.util.List; public class StringStartWithS { public static void main(String[] args) { List<String> strings = new ArrayList<>(); strings.add("sugar Apple"); strings.add("Sapodilla Fruit"); strings.add("Strawberry"); strings.add("salmonberry"); System.out.println("Given String : " + strings); boolean allStartWithS = strings.stream().allMatch(s -> s.startsWith("S") || s.startsWith("s")); if (allStartWithS) { System.out.println("All strings start with 'S' or 's'"); } else { System.out.println("Not all strings start with 'S' or 's'"); } } }
Given String : [sugar Apple, Sapodilla Fruit, Strawberry, salmonberry] All strings start with 'S' or 's'
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions