String str = "Hello World"; String sub = StringUtils.substring(str, 0, 5); // Extract "Hello"
String str = "Java Programming"; String sub = StringUtils.substring(str, "java", true); // Extract "Java"In this example, we use the substring method to extract the substring "Java" from the string "Java Programming", ignoring case. The package library for the StringUtils class is org.apache.commons.lang3.