Reputation: 29
I want to mask the first 4 digits of a stringed number, for example, 1234567 would look like ****567
Upvotes: 1
Views: 4631
Reputation: 1620
You could to this:
String str = "1234567";
String firstFourChars = str.substring(0, 4);
String newStr = str.replaceFirst(firstFourChars, "****");
Or to make it shorter:
str = str.replaceFirst(str.substring(0, 4), "****");
Upvotes: 1
Reputation: 1465
You can use the substring function. Try something like that
String number=1234567;
String maskNumber="****"+number.substring(4);
Upvotes: 2