How to Converter String to Integer having dots in java

I want converter a string to integer with string having dots:

String str = "10.000.000"; //Input is a String
//Output is a integer
int number;
//number = 10000000;

This should give you what you’re looking for.

String str = "10.000.000";
int number = Integer.parseInt(str.replace(".", ""));

You could use a regular expression with String.replaceAll, here we are replacing everything that is not a digit with “”. Like,

int number = Integer.parseInt(str.replaceAll("//D", ""));

which sets number to 10000000 (as requested). If you want to handle negative values, it could be extended to test for a – sign like

int number = (str.trim().startsWith("-") ? -1 : 1) *
        Integer.parseInt(str.replaceAll("//D", ""));
String strNumber = str.replace(".",""); // Remove dots
int number = Integer.parseInt(strNumber); // Parse String to number

What you’re doing is: parsing a number with the conventions of a country that is not the US.

The number format with dots as thousands-separators is used, for example, in Germany. You can do:

NumberFormat fmt = NumberFormat.getIntegerInstance(Locale.GERMAN);
int i = fmt.parse("10.000.000").intValue();
System.out.println(i);