Java wrapper class Integer Examples of

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45778981/article/details/102754285

The Java wrapper classes are in the API can be viewed in the java.lang package

Java wrapper class Integer Examples of

public class testInteger {
	
	public static void main(String[] args) {
		Integer i1=new Integer(123);
		Integer i2=new Integer("123");
		System.out.println((i1==i2));
		System.out.println(i1.equals(i2));
		System.out.println(i2.toString());//说明Integer类重写了toString方法

		//1.Integer-->int
		int i=i1.intValue();
		System.out.println(Integer.max(10,20));
		//2.int-->Integer
		Integer i4=Integer.valueOf(123);
		//3.String -->int
		int ii=Integer.parseInt("345");
		//4.int -->String
		String str=ii+"";
		String s=String.valueOf(ii);
		//5.string-->Integer
		Integer i5=new Integer("456");
		//6.Integer-->String
		String ss=i5.toString();
		System.out.println(ss);
		}
			
}

Guess you like

Origin blog.csdn.net/weixin_45778981/article/details/102754285