// java正则表达式的使用
public class Judge {
public static void main(String[] args) {
String regex = "\\w+@\\w+(\\.\\w{2,3})*\\.\\w{2,3}";
String str1 = "aaa@";
String str2 = "aaaaa";
String str3 = "1111@111ffyu.dfg.com";
System.out.println(str1.matches(regex));
if (str1.matches(regex)) {
System.out.println(str1 + "是一个合法的E-mail地址格式");
}
System.out.println(str2.matches(regex));
if (str2.matches(regex)) {
System.out.println(str2 + "是一个合法的E-mail地址格式");
}
System.out.println(str3.matches(regex));
if (str3.matches(regex)) {
System.out.println(str3 + "是一个合法的E-mail地址格式");
}
}
}
// 字符串操作之StringBuilder
public class Jerque {
public static void main(String[] args) {
String str = "";
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
str = str + i;
}
long endTime = System.currentTimeMillis();
System.out.println(str + " String 消耗时间: \n" + (endTime - startTime));
// StringBuilder的append方法a
StringBuilder builder = new StringBuilder("");
startTime = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
builder.append(i);
}
endTime = System.currentTimeMillis();
System.out.println(builder.toString() + " StringBuilder 消耗时间: \n" + (endTime - startTime));
// Stringbuilder的insert方法
StringBuilder bf = new StringBuilder("hello");
bf.insert(bf.toString().length(), "world");
System.out.println(bf.toString());
// StringBuilder的delete方法
StringBuilder bg = new StringBuilder("StringBuilder");
bg.delete(0, 6);
System.out.println(bg.toString());
}
}
Java study day five -- demo regex//StringBuilder
最新推荐文章于 2024-07-19 23:14:27 发布