Java knowledge point (5)

Source: Internet
Author: User

 

 

Large values and Arrays

1. Large Value

1.1 If the precision of the basic integers and floating-point numbers does not meet the requirements, you can use BigInteger and BigDecimal in the java. math package to process the values that contain any length sequence.

1.2 you can use the static valueOf method to convert a common value to a large value.

For example, BigInteger a = BigInteger. valueOf (100 );

1.3 do not use familiar Arithmetic Operators (such as + \ *) to process large numbers. Instead, use the add and mutilply methods in the large numeric class.

For example, BigInteger c = a. add (B) // equivalent to c = a + B;

2. Array

2.1 is a data structure used to store a set of values of the same type. Each value in the array is accessed through an integer subscript.

2.2 Method for declaring an array: int a [] or int []. Both methods are acceptable, but most java Programmers like the latter because it separates the int [] type from the variable name.

2.3 Once an array is created, its size cannot be changed. If the array is expanded frequently, you can use another data structure-array list ).

2.4 java SE 5.0 adds a strongly functional loop structure, which can process each element in the array in sequence without worrying about the array subscript.

Syntax: for (element variable used for traversal: Set variable) Processing statement;

For example, for (int element: a) System. out. printf (element );

In java 2.5, an array with a length of 0 is allowed. This method is used to compile an array. If the result happens to be null, this method is very useful.

For example, new elementType [0];

★The array with a length of 0 and null are different.

2.6 for the command line parameter array, the program name is not passed in, which is different from that in c ++.

2.7 For Array copying, retrieval, and sorting, you can use the related static methods in the Array class.

★Before java se6, System. arrayCopy was used to copy arrays.

2.8 java actually does not have multi-dimensional arrays. Only one-dimensional arrays can be interpreted as "arrays in arrays ".

★In java, double arr [10] [6] is equivalent to double ** arr = new double * [10] in c ++. Therefore, it can create an array with sertices.

This article is from the "Myworld" blog

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.