zoukankan      html  css  js  c++  java
  • 整理类型转换

    字符串和字节数组
    String str = "罗长";

    byte[] sb = str.getBytes();//字符串转字节数组
    byte[] b={(byte)0xB8,(byte)0xDF,(byte)0xCB,(byte)0xD9};

    String str= new String (b);//字节数组转字符串

    字符串和字符数组
    string str = "mytest";  
     char[] chars = str.ToCharArray(); //字符串转字符数组

    char[] chs = new char[]{’a’,’b’,’c’,’d’,’e’};

     String s4 = new String(chs); //字符数组转字符串

    字符串和基本数据类型
    int i=Integer.parseInt("123");//字符串转基本数据类型

    //基本数据类型转字符串的三种方法

    “sum”=1+1;//1.双引号:“”+基本数据类型

    String i=String.valueOf(122);//2.调用String类中的valueof方法

    String i=Double.toString(12.1);//3.调用包装类中独有的tostring方法



    基本数据类型和包装对象
    Integer i=new Integer(111);//基本数据类型转包装类型对象

    Integer i=Integer.valueOf(111);//封装成包装类型

    int num=i.intValue();//包装类转基本数据类型

  • 相关阅读:
    VS2013 使用QCustomPlot等三方库如何配置
    error LNK1112:模块计算机类型"X64" 与目标计算机类型"X86" 冲突
    Qt 获取屏幕当前分辨率
    流程控制
    导航条和工作内容纪要
    js简介
    高度塌陷
    浮动
    文档流
    display和overflow
  • 原文地址:https://www.cnblogs.com/marswenze/p/13330987.html
Copyright © 2011-2022 走看看