java应用技术 1(3)

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));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值