首页 > 编程语言 >Java: Wrapper Classes

Java: Wrapper Classes

时间:2022-11-27 20:00:51浏览次数:33  
标签:Java System Wrapper Classes myInt println Integer public out

Wrapper classes provide a way to use primitive data types (intboolean, etc..) as objects.

Primitive Data TypeWrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character

 

 

 

 

 

 

 

 

 

Sometimes you must use wrapper classes, for example when working with Collection objects, such as ArrayList, where primitive types cannot be used:

 

 For example, the following methods are used to get the value associated with the corresponding wrapper object: intValue()byteValue()shortValue()longValue()floatValue()doubleValue()charValue()booleanValue().

public class Main {
  public static void main(String[] args) {
    Integer myInt = 5; -> Integer
    Double myDouble = 5.99; -> Double
    Character myChar = 'A'; -> Character
    System.out.println(myInt.intValue()); -> int
    System.out.println(myDouble.doubleValue()); -> double
    System.out.println(myChar.charValue()); -> char
  }
}
public class Main {
  public static void main(String[] args) {
    Integer myInt = 100;
    String myString = myInt.toString();
    System.out.println(myString.length());
  }
}
// Outputs: 3

 

标签:Java,System,Wrapper,Classes,myInt,println,Integer,public,out
From: https://www.cnblogs.com/ShengLiu/p/16930474.html

相关文章

  • Java: Iterator
    An Iterator isanobjectthatcanbeusedtoloopthroughcollections,like ArrayList and HashSet.//ImporttheArrayListclassandtheIteratorclassi......
  • 线程总述(Java版)
    一、线程创建1、继承Thread类首先,自定义线程类继承THread类;其次,重写run方法,编写线程执行体;最后,创建线程对象并调用start()方法启动线程。但值得注意的是,线程并不一定......
  • 自用_Minecraft Java Server配置、指令等等提示
    尚未写完gamemode=(模式)//adventure冒险模式、creative创造模式、survival生存模式、spectator旁观者模式。online-mode=//用于验证玩家是否“在线”,也就是是否是正版......
  • 又一巨头从 Java 迁移到 Kotlin,简直很无语。。
    出品|OSC开源社区(ID:oschina2013)Meta发布了一篇博客表示,正在将其Android应用的Java代码迁移到Kotlin,并分享了这一过程中的一些经验。该公司认为,Kotlin是一种流行的......
  • java中时间表达
    初始化Datedate=newDate();输出时间字符串System.out.println(date.toString());字母           描述          ......
  • 学习Java掌握那些知识就入门了
    了解Java的基础Java基本语法、Java平台应用、Java的核心概念:JVM、JDK、JRE以及Java面向对象思想,同时要会学到如何在系统中搭建Java开发环境,以及如何利用第三方工具进行Jav......
  • Java开发学习(四十四)----MyBatisPlus查询语句之查询条件
    1、查询条件前面我们只使用了lt()和gt(),除了这两个方法外,MybatisPlus还封装了很多条件对应的方法。MybatisPlus的查询条件有很多:范围匹配(>、=、between)模糊匹......
  • Java基础_Spring三种构造方法
    第一种构造方法接口:FirstDaopackagecom.leehl.springgitider.dao;publicinterfaceFirstDao{publicvoidsave();}主方法:FirstDaoimplpacka......
  • java——mybatis——Mybatis的CRUD——查询返回行操作
    在第一个xml示例项目的基础上,进行操作: mybatis-config.xml配置文件:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEconfigurationPUBLIC"-//mybatis.org//DTDC......
  • java操作hdfs
    1.添加maven依赖,即在pom.xml文件李添加依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://......