There is also a lot faster solution for the problem:
String s = "009876.00".substring(0, s.indexOf('.'));
This test proves it:
---
String s = "009876.00";
long start = System.currentTimeMillis()
for(int i = 0; i < 1000000; i++) {
s.replaceAll("\\..*","");
}
System.out.println(System.
start = System.currentTimeMillis()
for(int i = 0; i < 1000000; i++) {
s.substring(0, s.indexOf('.'));
}
System.out.println(System.
---
Main Topics
Browse All Topics





by: CEHJPosted on 2007-06-17 at 08:45:37ID: 19302545
String s = " 009876.00".replaceAll("\\. .*", "");