8/30每日总结

异常处理

异常对象的对战信息

分为编译时的错误与运行时的错误
处理异常
try和catch

try{

}catch(Exception e){
    e.printStackTrace();//打印错误信息
}

多个错误可以用多个catch

finally 资源回收

无论是否出现异常都会被执行

throw

 [修饰符] void fun(参数) throws Exception,.... {
        throw new Exception("...");
}

throw new Exception() 抛出异常
throws Exception,….. 方法上定义

异常类

异常提示信息

堆栈信息:一层调用方法(错误直接方法)
二层调用方法
。。。。。。
自下而上是异常出现的代码所在方法的调用顺序的先后

常用类

Object

toString() :直接打印对象调用该方法
hashCode():返回该对象的内存地址

String

public class StringTest{
    public static void main(String[] args) {
        String str = "a|b|c|d|e";
        char s = str.charAt(0);//查找字符串的相应位置的字符 a
        System.out.println(s);
        String t = str.contains("d");//字符串是否包含“d” true
        System.out.println(t);
        System.out.println(str.indexOf("d"));//从前搜索相应字符第一次出现的位置
        System.out.println(str.indexOf("d"));//从后搜索相应字符第一次出现的位置
        String str2 = str.replace("a", "b");//替换a为b
        String[] strarray = str.split("\\|");//以|为分隔符将字符串分割存入数组
    }
}

StringBuffer

在进行大数据的字符串拼接时使用 StringBuffer

public class StringBufferTest {
    public static void main(String[] args) {
        SringBuffer x = new StringBuffer("");
        for (int i = 0; i < 100000; i++) {
            x.append(i);
        }
        System.out.println(x.length());
    }
}

Date

public class DateTest { 
    public static void main(String[] args) {
        Date d = new Date(); 
        System.out.println((d.getYear()+1900)+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日 "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss.SSS");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
        System.out.println(sdf.format(d));
        System.out.println(sdf2.format(d));

结果

2018年8月30日 20:33:16
2018年08月30日
2018年08月30日 20:33:16.335
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值