Answers for "separate int from string in input java"

1

java separate the numbers from string

// string contains numbers
        String str = "The price of the book is $49";
        // extract digits only from strings
        String numberOnly = str.replaceAll("[^0-9]", "");
        // print the digitts
        System.out.println(numberOnly);
Posted by: Guest on October-25-2021
0

java split int

String str = "1 16 217 22 992";

        String[] numbersAsStrings = str.split(" ");
        int[] numbers = new int[numbersAsStrings.length];

        for (int i = 0; i < numbersAsStrings.length; i++) {
            numbers[i] = Integer.parseInt(numbersAsStrings[i]);
        }
Posted by: Guest on March-06-2022

Code answers related to "separate int from string in input java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language