Split a String on Uppercase Characters: The given Java program takes an input string abCdefGHijkl and splits it into substrings based on the occurrence of uppercase letters. The resulting output separates the substrings wherever an uppercase letter is found, adding spaces between them. The output for the given input is ab Cdef G Hijkl.
Split a String on Uppercase Characters
package com.softwaretestingo.interviewprograms; import java.util.Arrays; public class InterviewPrograms42 { /* * Input =“abCdefGHijkl”; * Output: “ab Cdef G Hijkl” */ public static void main(String[] args) { String st = "abCdefGHijkl"; String[] r = st.split("(?=\\p{Upper})"); Arrays.stream(r).forEach(System.out::println); } }
Output
ab Cdef G Hijkl