java应用技术
1(3)
一、java的常用类库
1.StringBuffer类
:
1.StringBuffer sb = new StringBuffer();
2.反向操作reverse()
System.out.println(sb.reverse());
3.替换
replace
4.查找指点的内容是否存在
indexof()
2.Runtime类
1.每一个java虚拟机都对应了一个Runtime类的实例
案例:
Runtime r = Runtime.getRuntime();
System.out.println(r.freeMemory());
System.out.println(r.maxMemory());
String s ="haohaorena dsfa dsf ads fads f ads ";
System.out.println(s);
for(int i=0;i<50;i++){
s = s+i;
}
System.out.println(r.freeMemory());
System.out.println(r.maxMemory());
r.gc();
System.out.println(r.freeMemory());
3.System类(其方法全部是静态方法)
1.static void gc() 运行垃圾回收器。
2.static void exit(int status) 终止当前正在运行的 Java 虚拟机。
3.static long currentTimeMillis() 返回以毫秒为单位的当前时间。
4.static Properties getProperties() 确定当前的系统属性。
5.System.getProperties().list(System.out);
6.static String getProperty(String key) 获取指定键指示的系统属性。
4.日期操作类
1.Date 类
Date d = new Date();
System.out.println(d);
2.calendar类
Calendar c = new GregorianCalendar();
System.out.println(c.get(Calendar.YEAR));
System.out.println(c.get(Calendar.MONTH)+1);
3.DateFormat类
DateFormat d1 = DateFormat.getDateInstance();
DateFormat t1 = DateFormat.getTimeInstance();
System.out.println(d1.format(new Date()));
System.out.println(t1.format(new Date()));
DateFormat d2 = DateFormat.getDateInstance(DateFormat.YEAR_FIELD,new Locale("zh","cn"));
DateFormat t2= DateFormat.getTimeInstance(DateFormat.ERA_FIELD,new Locale("zh","cn"));
System.out.println(d2.format(new Date()));
System.out.println(t2.format(new Date()));
4.SimpleDateFormat
String strDate = "2012-10-01 11:10:10.222";
String formt1 = "yyyy-MM-dd HH:mm:ss.SSS";
String formt2 = "yyyy年MM月dd日HH时mm秒ss分SSS毫秒";
SimpleDateFormat sdf1 = new SimpleDateFormat(formt1);
SimpleDateFormat sdf2 = new SimpleDateFormat(formt2);
Date dd = null;
try {
dd = sdf1.parse(strDate );//这里只能是sdf1不能是sdf2
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(sdf2.format(dd));
1(3)
一、java的常用类库
1.StringBuffer类
:
1.StringBuffer sb = new StringBuffer();
2.反向操作reverse()
System.out.println(sb.reverse());
3.替换
replace
4.查找指点的内容是否存在
indexof()
2.Runtime类
1.每一个java虚拟机都对应了一个Runtime类的实例
案例:
Runtime r = Runtime.getRuntime();
System.out.println(r.freeMemory());
System.out.println(r.maxMemory());
String s ="haohaorena dsfa dsf ads fads f ads ";
System.out.println(s);
for(int i=0;i<50;i++){
s = s+i;
}
System.out.println(r.freeMemory());
System.out.println(r.maxMemory());
r.gc();
System.out.println(r.freeMemory());
3.System类(其方法全部是静态方法)
1.static void gc() 运行垃圾回收器。
2.static void exit(int status) 终止当前正在运行的 Java 虚拟机。
3.static long currentTimeMillis() 返回以毫秒为单位的当前时间。
4.static Properties getProperties() 确定当前的系统属性。
5.System.getProperties().list(System.out);
6.static String getProperty(String key) 获取指定键指示的系统属性。
4.日期操作类
1.Date 类
Date d = new Date();
System.out.println(d);
2.calendar类
Calendar c = new GregorianCalendar();
System.out.println(c.get(Calendar.YEAR));
System.out.println(c.get(Calendar.MONTH)+1);
3.DateFormat类
DateFormat d1 = DateFormat.getDateInstance();
DateFormat t1 = DateFormat.getTimeInstance();
System.out.println(d1.format(new Date()));
System.out.println(t1.format(new Date()));
DateFormat d2 = DateFormat.getDateInstance(DateFormat.YEAR_FIELD,new Locale("zh","cn"));
DateFormat t2= DateFormat.getTimeInstance(DateFormat.ERA_FIELD,new Locale("zh","cn"));
System.out.println(d2.format(new Date()));
System.out.println(t2.format(new Date()));
4.SimpleDateFormat
String strDate = "2012-10-01 11:10:10.222";
String formt1 = "yyyy-MM-dd HH:mm:ss.SSS";
String formt2 = "yyyy年MM月dd日HH时mm秒ss分SSS毫秒";
SimpleDateFormat sdf1 = new SimpleDateFormat(formt1);
SimpleDateFormat sdf2 = new SimpleDateFormat(formt2);
Date dd = null;
try {
dd = sdf1.parse(strDate );//这里只能是sdf1不能是sdf2
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(sdf2.format(dd));