Java Basics-Arrays and object-oriented

Source: Internet
Author: User

First, array-related

1. Variable parameters

When designing a method, the number of the last parameter of the method is variable, and the parameter of the change is called the variable parameter

New features added by jdk1.5, for cases where the number of parameters is ambiguous and the type is determined

Variable parameters are treated as arrays in Java

Precautions:

1. The variable parameter must be the last item in the formal parameter list

2, three points ... Between the variable type and the variable name, there are no spaces before or after it is possible.

2. Arrays Tool Class

Responsible for sorting, finding, and so on the array

Primarily for manipulating one-dimensional arrays

Java.util.Arrays

static method: Use the class name. Method name to call directly

Common methods:

1. Convert array sort contents to string output

String arrays.tostring (int[] array)

2. Array sort default Ascending

void Arrays.sort (int[] array)

3. Use binary Check table method: Gets the index of the specified element from the array

Return with no return negative

int Arrays.binarysearch (int[] array,int value)

4. Copy the specified array

4.1 int[] arrays.copyof (int[] array,int newlength)
Contains length number of lengths
4.2 int[] Arrays.copyofrange (int[] array,int from,int to)
The angle mark contains the head does not contain the tail [from,to]
5. Determine whether two arrays are equal
Boolean arrays.equals (int[] array1,int[] array2)
6. Populating an array with the specified elements
void Arrays.fill (int[] array, populated data)

3. Two-dimensional array

Concept:

Each element type in the array is a one-dimensional array

Example:

    

Defined:

    

   

Java Basics-Arrays and object-oriented

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.