import org.apache.commons.lang.StringUtils; String originalString = "Hello world!"; String substring = StringUtils.substring(originalString, 0, 3); // Result: "Hel"
import org.apache.commons.lang.StringUtils; String originalString = "Hello world!"; int length = originalString.length(); String substring = StringUtils.substring(originalString, length - 5, length); // Result: "world"
import org.apache.commons.lang.StringUtils; String originalString = null; String substring = StringUtils.substring(originalString, 0, 3); // Result: null String originalString = ""; String substring = StringUtils.substring(originalString, 0, 3); // Result: ""By using the substring method from the StringUtils class, you can easily manipulate and extract parts of a string in your Java programs, while also handling null or empty strings in a more graceful way.