Skip to main content

Java : How to find the counts of digits/numbers in a string using Java?


We can go with String method using regex pattern to find the count of valid digits in a string Input.


Example:

public class Test {
     public static void main(String[] args) {
         String inputStr = "1234 Number count test example using String method @@#@";
        System.out.println("Digits Count:"+(inputStr.length()-inputStr.replaceAll("[0-9]", "").length()));
         }


Output:

Digits Count:4



Comments

Popular posts from this blog

SAP - Java Application Development with Jco3 Connection

This is the post to explain the way of achieve the connection between non SAP Web application interacting with SAP backend RFC's through Jco3 connector. Mandatory Files: * sapjco3.jar (place in lib folder) * sapjco3.dll (required only windows based machine ,need to place under " C:\Windows\System32 " folder.) Required to download it from SAP market place with valid credentials,consider the version 32/64 bits depends on your work environment) Steps to connect SAP Backend: 1. Create a Stand alone/web application using any development tool. 2. Include jar and dll files in above specified folder 3. Create a connection class to connect backend with valid credentials 4. Create a service or consumer class with RFC call code to utilise the connection 5. Close the connection Make sure you have access and no firewall blocks for the SAP backend connection. Example Connection Code: sapConnect.java import com.sap.conn.jco.JCoDestination; import com.s...

Maven vs Gradle

What is Gradle? Gradle Build Tool is a fast, dependable, and adaptable open-source build automation tool with an elegant and extensible declarative build language. Gradle is a widely used and mature tool with an active community and a strong developer ecosystem. •            Gradle is the most popular build system for the JVM and is the default system for Android and Kotlin Multi-Platform projects. It has a rich community plugin ecosystem. •            Gradle can automate a wide range of software build scenarios using either its built-in functionality, third-party plugins, or custom build logic. •            Gradle provides a high-level, declarative, and expressive build language that makes it easy to read and write build logic. •            Gradle is fast, scalable, and can bui...

JSF2 with Mysql CRUD Web Application Demo

Java based CRUD demo application development with the combination of JSF2 framework ,Mysql database using Netbean IDE. Beginners can  understand initial configuration steps in JSF2  application development. Steps Followed: *  Install MySql Server with proper configuration and create some table with set of records or restore from your backup ,If you have anything. *  Download mySql Connector Drivers from official site. *  Install Netbean IDE with Server either Tomcat or Glassfish *  Create New Web Application and select the server and Framework (JSF2 used for this demo with Primefaces ). * Select the JPA framework to create a datasource connection and it will generate the the DAO and service classes based on Facade Design pattern. * Create JSF managed beans and Xhtml pages from the Pojo's (It's an automated process when you follow the video). * This video will help to understand the basic connection between frontend DAO's and business log...