2023.4.12潦草笔记

添加多个元素

List<String> list=List.of("jiuzhe","aaa");

过滤操作

list.stream().filter(name->name.startsWith("zhnag")).filter(name->name.length()==3)
.foreach.sout(name);

list转化为数组

  ArrayList<Integer> list=new ArrayList<>();
  Collections.addAll(list,1,2,3,4,0);//添加元素
  Integer arr[]=list.stream().toArray(Integer[]::new);
  System.out.println(Arrays.toString(arr));

throws

 public static void main(String[] args) throws ParseException {
        String time="2020年1月1日";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
        Date date=sdf.parse(time);//转换
        System.out.println(date);
    }

异常处理//需要注意的是,try里面出错了后面的内容就不执行了,直接跳到catch

父类的异常写在下面,如果catch的内容与实际错误不符合,相当于catch白写了,依旧会报错

try catch 的快捷键 ctrl +alt+t

 public static void main(String[] args)  {
       int arr[]={1};
       try {
           System.out.println(2/0);
           String s=null;
           System.out.println(s.equals("abc"));
           System.out.println(arr[2]);
       }catch (ArrayIndexOutOfBoundsException | ArithmeticException e){
           System.out.println("索引或者算术");
       }catch(NullPointerException e){
           System.out.println("空指针异常");
       }catch (Exception e){
           System.out.println("Exception");
       }
    }

判定条件

 if(arr==null) throw new NullPointerException();
 if(arr.length==0) throw new ArrayIndexOutOfBoundsException();

文件

public static void main(String[] args)  {
     String str="C\\a.txt";
     File file=new File(str);
     System.out.println(file);
     public File(String pathname)
    public File(String parent,String child)
    public File(File parent,String child);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值