Java Basic Data Type wrapper class (ix)

Source: Internet
Author: User

wrapper classes (e.g., integer,double, etc.) these classes encapsulate a corresponding base data type value and provide it with a series of operations.

Take the Java.lang.Integer class, for example, to construct the method:

Integer (int value);

Integer (String s);

Common methods:

public static final int max_value: Maximum int type (2^31-1)

public static final int min_value: Smallest int type ( -2^31)

Public long Longvalue (): Returns the Long value of the encapsulated data

Public double Doublevalue (): Returns the double type value of the encapsulated data

public int intvalue (): Returns the int type value of the encapsulated data

public static int parseint (string s) throws NumberFormatException: parses the string into int data and returns the data

public static integer valueOf (string s) throws NumberFormatException: Returns an Integer object in which the encapsulated integer data is represented by the string s.

Package mywrapperclass;

public class Test {

public static void Main (string[] args) {

TODO auto-generated Method Stub

Integer i=new integer (100);

Double D=new double ("123.456");

int J=i.intvalue () +d.intvalue ();

System.out.println ("J:" +j);

Float F=i.floatvalue () +d.floatvalue ();

System.out.println ("F:" +f);

Double pi=double.parsedouble ("3.1415926");

Double r=double.valueof ("2.0"). Doublevalue ();

Double s=pi*r*r;

System.out.println (s);

try{

int K=integer.parseint ("125.0");

}catch (NumberFormatException e) {

SYSTEM.OUT.PRINTLN ("The data format is wrong! ");

}

System.out.println (integer.tobinarystring (2) + "B");

System.out.println (integer.tohexstring (2) + "H");

System.out.println (integer.tooctalstring (2) + "O");

System.out.println (Integer.max_value);

System.out.println (Integer.min_value);

}

}

Writes a method that returns a double-type two-dimensional array in which the elements of the array are obtained by parsing the string parameters. such as the string parameter: "1,2;3,4,5;6,7,8".

Package mywrapperclass;

public class Teststringpractice {

public static void Main (string[] args) {

TODO auto-generated Method Stub

String s= "1,2;3,4,5;6,7,8";

String s1[]=s.split (";");

System.out.println (s1.length);

Double D[][]=new double[s1.length][];

for (int i=0;i<s1.length;i++) {

String temp[]=s1[i].split (",");

System.out.println (temp.length);

Defining a multidimensional array, defining a high dimension, int[][] a=new int[10][], and then defining a low dimension, you must define a low dimension because the memory is not allocated to the low dimension and the null pointer error is reported.

Low dimensional definition mode a[0]=new int[2];

D[i]=new Double[temp.length];

for (int j=0;j<temp.length;j++) {

D[i][j]=double.valueof (Temp[j]). Doublevalue ();

System.out.print (d[i][j]+ "");

}

System.out.println ();

}

}

}


This article is from the "one step, one step" blog, please be sure to keep this source http://summerflowers.blog.51cto.com/5202033/1923327

Java Basic Data Type wrapper class (ix)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.