Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java 1.5- What is meant by deeply equal or deep content

 
Afroz Ahmed
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
     
    Ko Ko Naing
    Ranch Hand
    Posts: 3178
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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!!!
     
    somkiat puisungnoen
    Ranch Hand
    Posts: 1312
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Nicholas Cheung
    Ranch Hand
    Posts: 4982
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Posts: 3178
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 64
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks,

    I got the purpose of 'deep'.Deep means 'nested' array.
     
    Nicholas Cheung
    Ranch Hand
    Posts: 4982
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Posts: 1312
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic