zoukankan      html  css  js  c++  java
  • Java 示例代码笔记(遗忘点)

    1.trim()

    Scanner scanner=new Scanner(System.in);

    String s=scanner.nextLine();

    //s=" SherlyHan "

    s.trim();

    //s="SherlyHan"  去掉String首尾的空格

    2.常见类型转换

    (1)String->int

    int s1=Integer.parseInt(string);

    int s1=Integer.valueOf(string).intValue();

    //int s1=Integer.valueOf(string);也是对的

    (2)int->String

    int i=1;

    String s=String.valueOf(i);//int i不被初始化,String 不能进行强制转换

    String s=Integer.toString(i);

    Stirng s=""+i;

    (3.1)String->Integer

    Integer integer=Integer.valueOf(string);

    (3.2)Integer->String

    Integer inte;

    String s=inte.toString();

    (4)Integer类->int变量名

    int i=integer.intValue();

    (5)int->Integer

    int i;

    Integer integer=new Integer(i);

    (6)String->char

    String s;

    char[] ch=s.toCharArray();

    ch.get(0);//只有一个char时

    (7)char->String

    String s=ch.toString();

    3.

    判断String是否相等:string.equals(S);

    4.IO

    (1)FileOutputStream out=new FileOutputStream(file);

    out.write(string.getBytes());

    (2)FileInputStream in=new FileInputStream(file);

    int i=in.read();

    while(i!=-1)

    {
    //得到的是编码

    i=in.read();

    }

    (3)BufferedReader br=new BufferedReader(new FileReader(f));

    String line;

    whie((line=br.readLine()) != null)

      System.out.println(line);

    (4)DataOutputStream dos=new DataOutputStream(new FileOutputStream(f));

    dos.writeInt(string.gertBytes().length);

    DataInputStream dis=new DataInputStream(new FileInputStream(f));

    byte[] buf=new byte[100];

    int len=dis.readInt();

    dis.read(buf,0,len);

    (5)ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(f));

    oos.writeobject(al.get(i));//ArrayList<type> al=new ArrayList();

    ObjectInputStream ois=new ObjectInputStream9new FileInputStream(f));

    object=(type)ois.readObject();//强制类型转化

    5.collection

    HashMap.containsKey(key);

    6.抽象类

    abstract calss Myclass<T>{

    protected abstract T peek();

    }

  • 相关阅读:
    Locust:简介和基本用法
    linux more less 用法
    Pytest测试用例之setup与teardown方法
    app测试之monkey
    理解yield以及和return的区别
    Python 数据驱动工具:DDT
    requests 使用 proxies 代理时ValueError: check_hostname requires server_hostname
    from urllib.parse import urlparse 使用
    linux 三剑客 使用总结 grep sed awk
    企查查和天眼查哪个好用
  • 原文地址:https://www.cnblogs.com/HackHer/p/5123506.html
Copyright © 2011-2022 走看看