1) There are three issues that distinguish arrays from other types of containers: efficiency, type, and the ability to hold primitives. The array is Java’s most efficient way to store and randomly access a sequence of object references. Arrays are superior to pre-generic containers because you create an array to hold a specific type. This means that you get compile-time type checking to prevent you from inserting the wrong type or mistaking the type that you’re extracting.
2) The array identifier is actually a reference to a true object that’s created on the heap. This is the object that holds the references to the other objects, and it can be created either implicitly, as part of the array initialization syntax, or explicitly with a new expression. Part of the array object (in fact, the only field or method you can access) is the read-only length member that tells you how many elements can be stored in that array object. The '[ ]' syntax is the only other access that you have to the array object.
Commented by Sean: another mehtod of array is clone which is overrided specifically for array.
3) when an array object is created, its references are automatically initialized to null. Similarly, an array of primitives is automatically initialized to zero for numeric types, (char)0 for char, and false for boolean.
4) The "aggregate initialization" syntax (i.e. {1,2,3} ) that causes the array object to be created (implicitly with new on the heap). The aggregate initialization must be used at the point of array definition but with the "dynamic aggregate initialization"(i.e. new int[]{1,2,3}) you can create and initialize an array object anywhere.
5) Java SE5 Arrays.deepToString( ) method turns multidimensional arrays into Strings. When you initialize multi-dimensional arrays , you can delimit each vector in the array by using curly braces.
6) Primitive array values are automatically initialized to zero if you don’t give them an explicit initialization value. Arrays of objects are initialized to null.
7) Each vector in the arrays that make up the matrix can be of any length, which is called a ragged array.
8) You cannot instantiate arrays of parameterized types. ( i.e. new HashMap<String>[10])You cannot create an array of a generic type. ( i.e. new T[10])
9) Although you cannot create an actual array object that holds generics, you can create an array of the non-generified type and cast it.
10) The Java standard library Arrays class has a rather trivial fill( ) method: It only duplicates a single value into each location, or in the case of objects, copies the same reference into each location.
11) All Collection subtypes have a toArray( ) method that will fill the argument array with the elements from the Collection.
12) In java.util, you’ll find the Arrays class, which holds a set of static utility methods for arrays. There are six basic methods: equals( ), to compare two arrays for equality (and a deepEquals( ) for multidimensional arrays); fill( ), to fill each element of an array with single value; sort( ), to sort an array; binarySearch( ), to find an element in a sorted array; toString( ), to produce a String representation for an array; and hashCode( ), to produce the hash value of an array. All of these methods are overloaded for all the primitive types and Objects. In addition, Arrays.asList( ) takes any sequence or array and turns it into a List container.
13) The Java standard library provides a static method, System.arraycopy( ), which can copy arrays far more quickly than if you use a for loop to perform the copy by hand. The arguments to arraycopy( ) are the source array, the offset into the source array from where to start copying, the destination array, the offset into the destination array where the copying begins, and the number of elements to copy. Naturally, any violation of the array boundaries will cause an exception.
14) To be equal, the arrays must have the same number of elements, and each element must be equivalent to each corresponding element in the other array, using the equals( ) for each element.
15) Java has two ways to provide comparison functionality:
a. The first is with the "natural" comparison method that is imparted to a class by implementing the java.lang.Comparable interface. This is a very simple interface with a single method, compareTo( ). This method takes another object of the same type as an argument and produces a negative value if the current object is less than the argument, zero if the argument is equal, and a positive value if the current object is greater than the argument. If Comparable hadn’t been implemented, then you’d get a ClassCastException at run time when you tried to call sort( ). This is because sort( ) casts its argument to Comparable.
b. You create a separate class that implements an interface called Comparator. This is an example of the Strategy design pattern. It has two methods, compare( ) and equals( ). However, you don’t have to implement equals( ) except for special performance needs, because anytime you create a class, it is implicitly inherited from Object, which has an equals( ). So you can just use the default Object equals( ) and satisfy the contract imposed by the interface. The Collections class contains a method reverseOrder( ) that produces a Comparator to reverse the natural sorting order.
16) The sorting algorithm that’s used in the Java standard library is designed to be optimal for the particular type you’re sorting—a Quicksort for primitives, and a stable merge sort for objects.
17) Arrays.binarySearch( ) produces a value greater than or equal to zero if the search item is found. Otherwise, it produces a negative value representing the place that the element should be inserted if you are maintaining the sorted array by hand. The value produced is : -(insertion point) - 1
The insertion point is the index of the first element greater than the key, or array.length, if all elements in the array are less than the specified key. If an array contains duplicate elements, there is no guarantee which of those duplicates will be found. If you sort an object array using a Comparator (primitive arrays do not allow sorting with a Comparator), you must include that same Comparator when you perform a binarySearch( ).
相关推荐
com.springsource.edu.emory.mathcs.backport-3.1.0.jar
Apress.PHP.Arrays.Single.Multi-dimensional.Associative.and.Object.Arrays.in.PHP.7.1484225554.rar 最新书籍,精讲PHP数组,文字版PDF
**JSTL(JavaServer Pages Standard Tag Library)** 是一个标准的Java标签库,用于增强JSP页面的功能,简化Web开发。它提供了多种标签来处理常见的任务,如控制流程、XML处理、数据库操作等,使得代码更加简洁和...
本章“Chapter 2. Arrays and Spatial Filters”深入探讨了这一主题,特别是聚焦于阵列与空域滤波的技术。下面将详细阐述其中的知识点。 一、阵列信号处理基础 阵列信号处理涉及多个传感器或天线同时接收信号的情况...
Using Java Arrays Chapter 5. Using Loops in Java Code Chapter 6. Encapsulating Data and Exposing Methods in Java Chapter 7. Using Java Methods to Communicate Chapter 8. Using Java Constructors ...
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System....
Chapter 16 - Dynamic Polymorphism—Object-Oriented Programming Part IV - Intermediate Chapter 17 - Well-Behaved Objects—The Orthodox Canonical Class Form Chapter 18 - Mixed Language ...
Chapter 16. Searching And Sorting. Chapter 17. Linked Lists. Chapter 18. Stacks And Queues. Appendix A. Reserved Words. Appendix B. Operator Precedence. Appendix C. Character Sets. Appendix D. ...
标题 "Arrays-0.0.4-py3-none-any.whl.zip" 提供的信息表明,这是一个包含 Python 软件包的压缩文件。在 Python 的生态系统中,`whl` 文件是预先编译的二进制分发格式,用于简化安装过程。这种格式通常由 `pip` 安装...
Slices: Windows Into Arrays Chapter 3. A Bigger Slice Chapter 4. The Ever-Versatile Map Chapter 5. Capstone: A Slice Of Life Unit 5 - STATE AND BEHAVIOR Chapter 1. A Little Structure Chapter 2. Go'S...
Arrays 5.6.1.1 - Declaring Arrays in Your Data Segment 5.6.1.2 - Accessing Elements of a Single Dimension Array 5.6.2 - Multidimensional Arrays 5.6.2.1 - Row Major Ordering 5.6.2.2 - ...
标题 "Arrays-0.0.5-py3-none-any.whl.zip" 提供的信息表明,这是一个包含 Python 软件包的压缩文件。在 Python 的生态系统中,".whl" 文件是预先编译的二进制包,用于简化安装过程。这种格式的文件通常由 Wheel 包...
import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class TaskScheduler { public static void main(String[] args) { Scanner scanner = new ...
java.Arrays(解决方案).md
Gain an in-depth understanding of PHP 7 arrays. After a quick overview of PHP 7, each chapter concentrates on single, multi-dimensional, associative, and object arrays. PHP Arrays is a first of its ...