Java Basics---Using the arrays class to manipulate arrays in Java (32)

Source: Internet
Author: User

Using the Arrays class to manipulate arrays in Java

The Arrays class is a tool class provided in Java, in the Java.util package. The class contains methods for manipulating arrays directly, such as sorting, searching, and so on (for classes and methods), which are explained in detail in a later section.

Common methods in Arrays:

1. Sorting

Syntax: 650) this.width=650; "src=" http://img.mukewang.com/537427720001012101670023.jpg "/>

You can use the sort () method to sort the array, as long as the array name is placed in parentheses of the sort () method to sort (in ascending order), such as 650) this.width=650; "src=" http:/ Img.mukewang.com/5374279d0001d9a706970392.jpg "/>

Operation Result:

650) this.width=650; "src=" http://img.mukewang.com/537427ec0001076602580140.jpg "/>

2. Converting an array to a string

Syntax: 650) this.width=650; "src=" http://img.mukewang.com/5374280f000191f202020022.jpg "/>

You can use the ToString () method to convert an array into a string, which connects multiple array elements sequentially, separated by commas and spaces between multiple elements, such as 650) this.width=650; "src=" http:/ Img.mukewang.com/537428a000010ea608880205.jpg "/>

Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/5374290a0001606604870024.jpg "/>

The Arrays class also provides a number of other ways to manipulate the array here is not listed here, and friends can read more on the wiki


Code:

Import Arrays Class
Import Java.util.Arrays;

public class HelloWorld {
public static void Main (string[] args) {

Defines a string array
String[] Hobbys = {"Sports", "Game", "movie"};

Use the sort () method of the arrays class to sort the array
Arrays.sort (Hobbys);

Use the ToString () method of the arrays class to convert the array to a string and output
System.out.println (arrays.tostring (Hobbys));
}
}



Operation Result:

[Game, movie, sports]

This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547984

Java Basics---Using the arrays class to manipulate arrays in Java (32)

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.