Java basic syntax-strings and Arrays

Source: Internet
Author: User
Basic Java syntax-string and array-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1. String:

Java does not provide built-in String types, but the standard Java library contains a predefined class, which is naturally called "String". Every String enclosed by double quotation marks is an instance of String.
Example: "abc", "hello"
Java allows the + sign to connect two strings. When a string is connected to a non-string value, the latter is converted to a string. This feature is often used in output statements.
Substring: Use the substring method provided by the String class to extract a substring from a large String.
In Java, the position of the first character in the string is 0,
You can use the length method to obtain the string length.
You can use charAt (n) to extract characters at position n.
You can use the equals method to determine whether two strings are equal. To check whether two strings are equal and ignore the differences between uppercase and lowercase letters, use the equalsIgnoreCase method.
You cannot use = to determine whether two variables are equal.

2. array:

In Java, arrays are the first type of objects. After an array is created, its size cannot be changed easily. When you try to access any element outside the boundary of the array declaration, the program runs and stops, but you can run the command during compilation.
Java creates an array object and provides the abbreviated form of initialization values:
Int [] smallPrimes = {2, 3, 4, 5, 6 };
You can also Initialize an "anonymous array ":
New int [] {2, 3, 4, 5, 6 };
When an array is used as a method parameter and you do not want to create a local array variable to save the array, you can use the anonymous array method.
If you want to know the number of elements contained in an array, you can use the arrayName. length method.
Array replication: You can copy one array variable to another, but both variables reference the same array. You can use
System. arraycopy (from, fromIndex, to, toIndex, count); method.
Array is used as a parameter: array in Java is used as a parameter, and the reference method is used, that is, the address of the passed array, changing the value of the array element in the method can change the value of the source array element.
Array as the return value: A method can return an array.

Multi-dimensional array:

A two-dimensional array can be defined in Java, but there is no multi-dimensional array. Multi-dimensional arrays are actually implemented through arrays.
Related Article

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.