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( ).
相关推荐
Protein.Arrays,.Biochips,.and.Proteomics.-.Joanna.S.Albala
Apress.PHP.Arrays.Single.Multi-dimensional.Associative.and.Object.Arrays.in.PHP.7.1484225554.rar 最新书籍,精讲PHP数组,文字版PDF
in production environments and one that is recommended to be used in ; development environments. ; php.ini-production contains settings which hold security, performance and ; best practices at its ...
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 ...
It provides a thorough understanding of the subject and its applications. The book begins with an introduction to the basic features of a digital computer, number systems and ...Chapter 16. Advanced C
Beginning with the basic concept of programming, the book gives an exhaustive coverage of arrays, strings, functions, pointers, and data structures. Separate chapters on linked lists and stacks, ...
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. ...
[U.Meyer-Baese]Digital Signal Processing with Field Programmable Gate Arrays.3rd Ed
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 - ...
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 ...
Chapter 16. Files and Their Organization Appendix A: Memory Allocation in C Programs Appendix B: Garbage Collection Appendix C: Backtracking Appendix D: Josephus Problem Appendix E: File Handling in C...
Arrays 马克-to-win Java视频 数组的详细描述介绍
Chapter 16 The Single-Alternative Decision Structure Chapter 17 The Dual-Alternative Decision Structure Chapter 18 The Multiple-Alternative Decision Structure Chapter 19 The Case Decision Structure ...
4.2 Using Arrays as Lookup Tables .......................................................................................4-6 4.3 Using Hash Objects as Lookup Tables.......................................
Data Structures and Algorithms in Java - 4 Introduction - 7 Part I Chapter 1 - Overview - 11 Chapter 2 - Arrays - 29 Chapter 3 - Simple Sorting - 63 Part II Chapter 4 - Stacks and ...
Functions in Class Hierarchies 618 Section 13.3. Polymorphism 629 Section 13.4. Abstract Base Classes 649 Chapter Review 661 Chapter 14. Files 664 Section 14.1. Input/Output Streams 665 ...
In this book, he doesn't just tell you what's wrong with C++, but offers practical techniques and tools for writing code that's more robust, flexible, efficient, and maintainable. He shows you how to...