

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removing leading zeros from a String using apache commons library in Java
The stripStart() method of the org.apache.commons.lang.StringUtils class accepts two strings and removes the set of characters represented by the second string from the string of the first string.
To remove leading zeros from a string using apache communal library −
Add the following dependency 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 first parameter and a string holding 0 as second parameter to the stripStart() method of the StringUtils class.
Example
The following Java program reads an integer value from the user into a String and removes the leading zeroes from it using the stripStart() method of the StringUtils class.
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); } }
Output
Enter a String: 000Hello how are you Hello how are you
- Related Questions & Answers
- Remove Leading Zeros From String in Java
- Remove Leading Zeros from a String in C#
- Remove Leading Zeros from an Array using C++
- Add leading Zeros to Python string
- Add leading Zeros to Python Program string
- Java Program to Remove leading zeros
- Remove Leading Zeroes from a String in Java using regular expressions
- How to remove leading zeros from a number in JavaScript?
- Removing punctuations from a string using JavaScript
- Java Program to add leading zeros to a number
- Remove leading zeros in a JavaScript array?
- Removing all spaces from a string using JavaScript
- Add leading zeros to a MySQL column?
- Remove leading zeros in array - JavaScript
- Explain how to remove Leading Zeroes from a String in Java
Advertisements