zoukankan      html  css  js  c++  java
  • 第六节:详细讲解Java中的装箱与拆箱及其字符串

    前言

    大家好,我是 Vic,今天给大家带来详细讲解Java中的装箱与拆箱及其字符串的概述,希望你们喜欢

    装箱与拆箱

    封装类有:Byte , short , Integer , Character , long , Float , Double 记住这些类就可以了,这些都是Number的子类。

    了解装箱与拆箱的代码解析

    public class Test{
     public static void main(String[] args){
      int i = 5;
      Integer integer = new Integer(i);//装箱
      //拆箱
      int i2 = integer.intValue();
     }
    }
    //
    public class Test{
     public static void main(String[] args){
      int i = 5;
      Integer integer = new Integer(i);
      Interger i2 = i;//自动装箱
      int i3 = integer;//自动拆箱
     }
    }
    //
    public class Test{
     public static void main(String[] args){
      char c = 'Vic';
      character c2 = c;
      c3 = c2;
      }
    }
    

    字符串

    public class Test{
     public static void main(String[] args){
      int i = 12;
      String str = String.valueof(i);
      System.out.println(str);
     }
    }
    
    public class Test{
     public static void main(String[] args){
      int i = 12;
      Integer i2 = i;
      String str = i2.toString();
      }
    }
    

    要点

    charAt , toCharArray , subString , split , toLowerCase , toUpperCase 等。

    StringBuffer , StringBuilder , String的区别

    • 效率:StringBuilder > StringBuffer > String

    String 为不可改变的字符串常量;
    StringBuffer 为线程安全的字符串变量
    StringBuilder 为线程非安全的字符串变量

    总结

    • 本文讲了详细讲解Java中的装箱与拆箱及其字符串,如果您还有更好地理解,欢迎沟通
    • 定位:分享 Android&Java知识点,有兴趣可以继续关注
  • 相关阅读:
    If you want the rainbow, you have to deal with the rain.
    Yesterday is history, tomorrow is a mystery, but today is a gift.
    .bashrc修改环境变量文件后ls之类的不能用了
    Flask项目中使用mysql数据库启动项目是发出警告
    flask 编码问题
    flask 密钥问题
    Flask 数据库连接
    查看cpu核的相关信息
    top命令常用
    gluster设置日志级别
  • 原文地址:https://www.cnblogs.com/dashucoding/p/11932679.html
Copyright © 2011-2022 走看看