final class Playground {
private static List<Double> extract(final String input) {
final List<Double> results = new LinkedList<>();
StringBuilder builder = new StringBuilder(1);
for (final char character : input.toCharArray()) {
if (Character.isDigit(character) || (Character.compare(character, '.') == 0)) {
builder.append(character);
} else {
results.add(Double.valueOf(builder.toString()));
builder = new StringBuilder(1);
}
}
if (builder.length() > 0) {
results.add(Double.valueOf(builder.toString()));
}
return results;
}
public static void main(final String... args) {
System.out.printf("[numbers] %s", Playground.extract("12*2/5-3.0^3.23"))
}
}
這沒有幫助。這是做什麼的?這是如何回答這個問題的? –
我也想要包含特殊字符,如+, - ,*,^。 –