We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 487c950 commit 8f41ea5Copy full SHA for 8f41ea5
src/main/java/com/string/ReplaceFirstDemo.java
@@ -0,0 +1,30 @@
1
+package com.string;
2
+
3
+/**
4
+ * @Author: EnjoyCoding
5
+ * @Date: 2020\4\9 0009 23:16
6
+ * @Description:
7
+ */
8
+public class ReplaceFirstDemo {
9
10
+ public static void main(String[] args) {
11
+ String test="a b c defg ";
12
+ int count = replaceSpaceCount(test);
13
+ System.out.println(count);
14
+ }
15
16
+ public static int replaceSpaceCount(String str) {
17
+ if (str == null) {
18
+ return 0;
19
20
+ int count=0;
21
+ while (str.contains(" ")) {
22
+ str = str.replaceFirst(" ", "");
23
+ count++;
24
25
+ System.out.println(str);
26
+ return count;
27
28
29
30
+}
0 commit comments