/**
* demo
*/
package demo;
/**
* @author Wu Zhenzhen
* @version Jul 25, 2012 11:04:57 AM
*
*/
public class SubstringDemo
{
/**
* <p />
* Jul 25, 2012 11:04:57 AM
*
* @param args
*/
public static void main(String[] args)
{
// while (true)
{
String str = "fjdskfksljflksjfkldsjflksdjflksjfkldsjflkdsjfldsjklfsjdflkdsjfklsdjflklfj:3ljkljkljlkjlsjoeiwruoweru9032uro3wrjlskfjlsajlasjflsadfioewuo uwoir ewlrjewklqfjwlfjoewiruoqwreowifjadslfjlasdhflaskdfiowuaio2342dsf:9-090sf:fsfds";
long start = System.currentTimeMillis();
String stra[] = str.split(":");
String m1 = stra[0];
String m2 = stra[1];
String m3 = stra[2];
String m4 = stra[3];
System.out.println("m1 = " + m1);
System.out.println("m2 = " + m2);
System.out.println("m3 = " + m3);
System.out.println("m4 = " + m4);
long end = System.currentTimeMillis();
System.out.println("split use times : " + (end - start) + " ms");
start = System.currentTimeMillis();
int idx1 = str.indexOf(":");
int idx2 = str.indexOf(":", idx1 + 1);
int idx3 = str.indexOf(":", idx2 + 1);
m1 = str.substring(0, idx1);
m2 = str.substring(idx1 + 1, idx2);
m3 = str.substring(idx2 + 1, idx3);
m4 = str.substring(idx3 + 1, str.length());
System.out.println("m1 = " + m1);
System.out.println("m2 = " + m2);
System.out.println("m3 = " + m3);
System.out.println("m4 = " + m4);
end = System.currentTimeMillis();
System.out
.println("substring use times : " + (end - start) + " ms");
System.out
.println("----------------------------------------------");
}
}
}
m1 = fjdskfksljflksjfkldsjflksdjflksjfkldsjflkdsjfldsjklfsjdflkdsjfklsdjflklfj
m2 = 3ljkljkljlkjlsjoeiwruoweru9032uro3wrjlskfjlsajlasjflsadfioewuo uwoir ewlrjewklqfjwlfjoewiruoqwreowifjadslfjlasdhflaskdfiowuaio2342dsf
m3 = 9-090sf
m4 = fsfds
split use times : 70 ms
m1 = fjdskfksljflksjfkldsjflksdjflksjfkldsjflkdsjfldsjklfsjdflkdsjfklsdjflklfj
m2 = 3ljkljkljlkjlsjoeiwruoweru9032uro3wrjlskfjlsajlasjflsadfioewuo uwoir ewlrjewklqfjwlfjoewiruoqwreowifjadslfjlasdhflaskdfiowuaio2342dsf
m3 = 9-090sf
m4 = fsfds
substring use times : 0 ms
----------------------------------------------
m1 = fjdskfksljflksjfkldsjflksdjflksjfkldsjflkdsjfldsjklfsjdflkdsjfklsdjflklfj
m2 = 3ljkljkljlkjlsjoeiwruoweru9032uro3wrjlskfjlsajlasjflsadfioewuo uwoir ewlrjewklqfjwlfjoewiruoqwreowifjadslfjlasdhflaskdfiowuaio2342dsf
m3 = 9-090sf
m4 = fsfds
split use times : 5 ms
m1 = fjdskfksljflksjfkldsjflksdjflksjfkldsjflkdsjfldsjklfsjdflkdsjfklsdjflklfj
m2 = 3ljkljkljlkjlsjoeiwruoweru9032uro3wrjlskfjlsajlasjflsadfioewuo uwoir ewlrjewklqfjwlfjoewiruoqwreowifjadslfjlasdhflaskdfiowuaio2342dsf
m3 = 9-090sf
m4 = fsfds
substring use times : 0 ms
----------------------------------------------