zoukankan      html  css  js  c++  java
  • JAVA备忘录

    本文主要是记录一下JAVA:

    1.Arrays.的几个用法:

    fill:数组全部置一个数

    sort:排序

    binarySearch:二分查找

    2.Map的用法:

    Map<Integer,Integer> ma = new HashMap<Integer,Integer>();
    
    ma.put(key, val);
    
    int val = ma.get(key); // key没有的话,为null,所以需要先判断是否为null
    

      

    3.Math.的用法

    4.文件操作:

    FileInputStream in = new FileInputStream("src\data.txt");
    DataInputStream fin = new DataInputStream(in);
    
    String s = fin.readLine();
    
    
    FileOutputStream out = new FileOutputStream("src\ans.txt");
    DataOutputStream fout = new DataOutputStream(out);
    fout.writeBytes("string");
    

      

    Scanner cin = new Scanner(new File("file.txt"));
    

      

    5.日期操作:

    设置格式:DateFormat format = new SimpleDateFormat("yyyy:MM:dd");
    
    得到某个日期:Date a = format.parse(string);
    
    得到两个日期相差的天数:int day =(int) ( (a.getTime()-b.getTime())/(24*60*60*1000) );
    
    得到从0000:00:00开始经过num毫秒数的日期:a.setTime(num);
    
    得到某个格式format的日期的字符串格式:String str = format.format(a);
    

      

    6.foreach:

    int [] a = new int[100];
    for(int c:a)
        a[i] = i;
    

      

  • 相关阅读:
    进程同步&&进程互斥
    CHAP4 字符串和格式化输入输出
    记录学习到的内容
    数据链路层 差错控制
    二叉树的顺序存储
    Java复习笔记
    Stream流
    函数式接口
    网络编程
    接口,多态,抽象类总结
  • 原文地址:https://www.cnblogs.com/yejinru/p/3474593.html
Copyright © 2011-2022 走看看