Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 使用StringBuilder优化了字符串拼接 #222

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: 使用StringBuilder优化了字符串拼接
将StringUtil.java类中三处字符串直接拼接优化为使用StringBuilder拼接
issue #182
Rkyzzy committed Apr 22, 2021
commit ab5c047d3160c6cc788aae8e8d536f4773b42099
21 changes: 11 additions & 10 deletions APIJSONORM/src/main/java/apijson/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static String getString(Object[] array, String split) {
* @return
*/
public static String getString(Object[] array, String split, boolean ignoreEmptyItem) {
String s = "";
StringBuilder s = new StringBuilder("");
if (array != null) {
if (split == null) {
split = ",";
Expand All @@ -127,10 +127,10 @@ public static String getString(Object[] array, String split, boolean ignoreEmpty
if (ignoreEmptyItem && isEmpty(array[i], true)) {
continue;
}
s += ((i > 0 ? split : "") + array[i]);
s.append(((i > 0 ? split : "") + array[i]));
}
}
return getString(s);
return getString(s.toString());
}

//获取string,为null时返回"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down Expand Up @@ -540,20 +540,19 @@ public static String getNumber(String s, boolean onlyStart) {
return "";
}

String numberString = "";
StringBuilder numberString = new StringBuilder("");
String single;
for (int i = 0; i < s.length(); i++) {
single = s.substring(i, i + 1);
if (isNumer(single)) {
numberString += single;
numberString.append(single);
} else {
if (onlyStart) {
return numberString;
return numberString.toString();
}
}
}

return numberString;
return numberString.toString();
}

//提取特殊字符>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down Expand Up @@ -643,14 +642,16 @@ public static String getPrice(String price, int formatType) {
}

//单独写到getCorrectPrice? <<<<<<<<<<<<<<<<<<<<<<
String correctPrice = "";
String correctPrice;
StringBuilder correctPriceBuilder = new StringBuilder("");
String s;
for (int i = 0; i < price.length(); i++) {
s = price.substring(i, i + 1);
if (".".equals(s) || isNumer(s)) {
correctPrice += s;
correctPriceBuilder.append(s);
}
}
correctPrice = correctPriceBuilder.toString();
//单独写到getCorrectPrice? >>>>>>>>>>>>>>>>>>>>>>

Log.i(TAG, "getPrice <<<<<<<<<<<<<<<<<< correctPrice = " + correctPrice);
Expand Down