| Author |
Java 1.5- What is meant by deeply equal or deep content
|
Afroz Ahmed
Ranch Hand
Joined: Jan 18, 2004
Posts: 64
|
|
Hello, The Java 1.5 API specifies that: Arrays.deepEquals (Object[],Object[]) Returns true if the two specified arrays are deeply equal to one another What is meant by 'deeply' equal to.What the other ways of equals? What is the difference between Arrays.toString(Object) and Arrays.deepToString(Object[]) ? [ August 24, 2004: Message edited by: Afroz Ahmed ]
|
The value of an idea lies in the usage of it.
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Arrays.deepEquals (Object[],Object[]) Returns true if the two specified arrays are deeply equal to one another
It is useful for nested array i.e. each element of the Object passed is an array itself. deepToString -Useful to print nested array. Arrays.toString .. Print 1-D array.
|
Groovy
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
What is meant by 'deeply' equal to.What the other ways of equals?
From the API description, we may expect that this method focus on array objects that contains array as well, such as arrays of arrays. In such case, the normal equals() method may not work well. You can refer to the API:
Returns true if the two specified arrays are deeply equal to one another. Unlike the @link{#equals{Object[],Object[]) method, this method is appropriate for use with nested arrays of arbitrary depth. Two array references are considered deeply equal if both are null, or if they refer to arrays that contain the same number of elements and all corresponding pairs of elements in the two arrays are deeply equal. Two possibly null elements e1 and e2 are deeply equal if any of the following conditions hold: e1 and e2 are both arrays of object reference types, and Arrays.deepEquals(e1, e2) would return true e1 and e2 are arrays of the same primitive type, and the appropriate overloading of Arrays.equals(e1, e2) would return true. e1 == e2 e1.equals(e2) would return true. Note that this definition permits null elements at any depth. If either of the specified arrays contain themselves as elements either directly or indirectly through one or more levels of arrays, the behavior of this method is undefined.
Thus, you can see that, it is not only simply compare with the components of 2 arrays at position i, but also the recursive content. Nick
|
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
|
 |
Ko Ko Naing
Ranch Hand
Joined: Jun 08, 2002
Posts: 3178
|
|
this method is appropriate for use with nested arrays of arbitrary depth.
Oh, Imagine if we got three nested arrays like 3-D arrays... I think it would be very rare case that an application have more than 4-D arrays nested... Mmm, it's sort of beyond the the ability of imagination for a programmer... What a robust method deepEquals is!!!
|
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
I think this code example shoule be help you to understand in Arrays.deepToString(Objcect[]) Output ::
---------- run ---------- ToString : [[Ljava.lang.String;@7d772e, null, null] DeepToString : [[11, 12], null, null] QUOTE] This method is useful for display multi-dimension of array.
|
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
Oh, Imagine if we got three nested arrays like 3-D arrays... I think it would be very rare case that an application have more than 4-D arrays nested... Mmm, it's sort of beyond the the ability of imagination for a programmer... What a robust method deepEquals is!!!
In fact, there are lots of features that may not be used frequently, however, US architects usually will think more than necessary. Just think about it, for example, Oracle10g aims on Grid platform, but, how many companies which use Oracle10g will really have a Grid platform? They just work it out, and in case, you really wanna to use those features, there are! Nick
|
 |
Ko Ko Naing
Ranch Hand
Joined: Jun 08, 2002
Posts: 3178
|
|
Originally posted by Nicholas Cheung: In fact, there are lots of features that may not be used frequently, however, US architects usually will think more than necessary.
What about European architects like those in Nokia and Asian architects like those in Sony? I do agree with you that we got more than we need in technology fields... For example, I am using JBuilder X, Enterprise Edition, which the company I am working for bought it and I don't know all the features available in version X... not even in version 8 and 9... So we got more than we need...
|
 |
Afroz Ahmed
Ranch Hand
Joined: Jan 18, 2004
Posts: 64
|
|
Thanks, I got the purpose of 'deep'.Deep means 'nested' array.
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
What about European architects like those in Nokia and Asian architects like those in Sony
Although there are lots of expertises over the world, I still believe US people will be the leader of the world, especially in technology aspects. Nick
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
Originally posted by Afroz Ahmed: Thanks, I got the purpose of 'deep'.Deep means 'nested' array.
Right ... This method is designed for converting multidimensional arrays to strings.
|
 |
 |
|
|
subject: Java 1.5- What is meant by deeply equal or deep content
|
|
|