Home > Java > javaTutorial > body text

Detailed explanation of the advantages and disadvantages of arrays in Java

Y2J
Release: 2017-05-17 09:04:12
Original
2695 people have browsed it

This article will give you a brief introduction to the advantages and disadvantages of Java arrays. Friends who need it can refer to it

Arrays are one of the basic knowledge of Java language. After in-depth study of the basics of Java, we all know Those containers, in the future, we will basically use containers in the process of our study and work. We rarely use arrays, so why do we need arrays? I only encountered this problem today, and I looked for information to study it. .

There are three differences between arrays and other types of containers: efficiency, type, and the ability to save basic types. Of course, now that there are generics, the difference in saved types is not big.

The biggest advantage of arrays over containers is efficiency. In Java, an array is the most efficient way to store and randomly access objectreferencesequences. An array is a simple linear sequence, which makes element access very fast, regardless of use Which type of array? The array identifier is actually just a reference, pointing to a real object created in the heap. This (array) object is used to save references to other objects. Arrays are first-level objects that can be created implicitly as part of an array initialization statement or explicitly with the Newexpression.

The advantage of arrays is high efficiency, but the price paid is that the size of the array object is fixed. This also makes arrays impractical when working with certain data volumes that are not fixed. At this time, you need to prefer containers instead of arrays. A project should be refactored to use arrays only if performance has proven to be an issue and if it is determined that switching to arrays will help performance.

【Related Recommendations】

1. Special Recommendation:"php Programmer Toolbox" V0.1 version Download

2. Java free video tutorial

3. Comprehensive analysis of Java annotations

The above is the detailed content of Detailed explanation of the advantages and disadvantages of arrays in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template