zoukankan      html  css  js  c++  java
  • 第四周总结

    1.时期类:

    1):Calendar 为抽象方法,创建其对象只能用 Calendar cal=Calendar.getInstance()来创建。

    2):在SimpleDateFormat中,将字符串转换成Date:Date a=format.parse(str);反之为String str=format.format(a);

    2.集合类:

    1):List<Integer>numbers=new ArrayList<>();  升序排序:Collections.sort(numbers);,逆序排序:Collections.reverse(numbers);

    2):若元素不是数字,不能直接排序,则需要使用匿名内部类

    eg:Collections.sort(stus, new Comparator<Student>(){
                @Override
                public int compare(Student o1, Student o2) {
                    // TODO Auto-generated method stub
                    return o1.getAge()-o2.getAge();
                }

                Comparator为比较器  匿名方法为compare,形参有两个对象进行比较
                Comparable为可以比较,匿名方法为compareTo,形参为一个对象

    3):在map类中,使用Set<String>keys=map.keySet()来接收键的集合,因为键是无序的,所有用set集合来接收

    3.文件类:

    1):在读取文本文件内容时

    try {
                FileReader reader = new FileReader("F:\hello.txt");找到文件
                StringBuffer sb = new StringBuffer();
                int n;
                while ((n=reader.read())!=-1) {reader.read返回的是第一个char字符对应的int数值,这里创建sb来添加所有字符,当reader.read=-1时,表示下一位没有字符
                        sb.append((char)n);
                }
                System.out.println(sb);
                reader.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

  • 相关阅读:
    计算机网络知识 第一部分
    LAMP环境安装
    Axure RP 交互设计
    Axure RP 界面功能
    Axure RP 界面功能介绍
    Axure RP 第一部分
    Grub管理修改root口令
    MYSQL 部分练习题
    工作日志示例
    计算机网络的分类
  • 原文地址:https://www.cnblogs.com/Onedayzk/p/5792306.html
Copyright © 2011-2022 走看看