org.apache.commons.lang.StringUtils The stripStart() method accepts two strings and extracts them from the strings Removes the character set represented by the second string. The string of the first string.
Remove leading zeroes from string using apache common library -
Add the following dependencies to your pom .xml file
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.9</version> </dependency>
Get the string.
Pass the obtained string as the first parameter and the string containing 0 as the second parameter to Strong>stripStart( of the < < StringUtils class ) method.
The following Java program reads and converts the user's integer value into a string and uses the stripStart() method of the StringUtils class from Remove leading zeros.
import java.util.Scanner; import org.apache.commons.lang3.StringUtils; public class LeadingZeroesCommons { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a String: "); String str = sc.nextLine(); String result = StringUtils.stripStart(str, "0"); System.out.println(result); } }
Enter a String: 000Hello how are you Hello how are you
The above is the detailed content of Remove leading zeroes from string using Apache Commons library in Java. For more information, please follow other related articles on the PHP Chinese website!