sort method for a 2D object array?

J

Jeff

Does anyone know of a publicly available sort method for a 2 dimensional
object array? I have a 2 dimensional object array which I would like to
sort according to the values in the second column.

There's a Swing example using TableModels, but a TableModel is a convoluted
solution to my simple problem.

Thanks
 
C

Chris Smith

Jeff said:
Does anyone know of a publicly available sort method for a 2 dimensional
object array? I have a 2 dimensional object array which I would like to
sort according to the values in the second column.

Depending on your conception of "row" and "column" in the array,
Arrays.sort may work with a custom Comparator. Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Tony Morris

Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

Not quite.
A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array.

Java has no 2 dimensional arrays (despites false claims, even by the JLS
itself); it only has arrays of arbitrary type - they are not synonymous.
http://www.xdweb.net/~dibblego/java/faq/answers.html#q45
 
C

Chris Smith

Tony Morris said:
Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

Not quite.
A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array.

Java has no 2 dimensional arrays (despites false claims, even by the JLS
itself); it only has arrays of arbitrary type - they are not synonymous.

I'm not sure what distinction you're trying to make. As near as I can
tell, what you said is exactly identical to what I said. Yet you say
you don't agree with me. Can you clarify?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
P

Patricia Shanahan

Chris said:
Tony Morris said:
Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

Not quite.
A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array.

Java has no 2 dimensional arrays (despites false claims, even by the JLS
itself); it only has arrays of arbitrary type - they are not synonymous.


I'm not sure what distinction you're trying to make. As near as I can
tell, what you said is exactly identical to what I said. Yet you say
you don't agree with me. Can you clarify?

Your comment could be interpreted in either of two ways:

1. Any so-called 2-D array, in any language, is nothing but
an array whose elements are arrays.

2. What is called a 2-D array in Java is nothing but an
array whose elements are arrays.

Tony's comment rebuts #1 but agrees with #2.

Patricia
 
X

xarax

Patricia Shanahan said:
Chris said:
Tony Morris said:
Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

Not quite.
A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array.

Java has no 2 dimensional arrays (despites false claims, even by the JLS
itself); it only has arrays of arbitrary type - they are not synonymous.


I'm not sure what distinction you're trying to make. As near as I can
tell, what you said is exactly identical to what I said. Yet you say
you don't agree with me. Can you clarify?

Your comment could be interpreted in either of two ways:

1. Any so-called 2-D array, in any language, is nothing but
an array whose elements are arrays.

2. What is called a 2-D array in Java is nothing but an
array whose elements are arrays.

Tony's comment rebuts #1 but agrees with #2.

Patricia

Welcome back, Patricia!
 
T

Tony Morris

Chris Smith said:
Tony Morris said:
Remember that a so-
called "two-dimensional array" is really nothing but an array whose
elements are arrays.

Not quite.
A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array.

Java has no 2 dimensional arrays (despites false claims, even by the JLS
itself); it only has arrays of arbitrary type - they are not synonymous.

I'm not sure what distinction you're trying to make. As near as I can
tell, what you said is exactly identical to what I said. Yet you say
you don't agree with me. Can you clarify?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

I can't see the ambiguity, but yourself and Patricia suggest there is one,
so I'll try to rephrase.

"A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is
a
2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array."

I think we all agree with this.

"two-dimensional array is really nothing but an array whose elements are
arrays."

This is the part that is not true.
A two-dimensional array is certainly not an array of arrays and vice versa.
They are not synonymous; the only real relationship is that one may
conceptualise each in a similiar fashion.
C# allows both "arrays of arrays" as Java does, as well as multi-dimensional
arrays.
COBOL has always had the TABLE construct, which is a multi-dimensional
array.
Java has no multi-dimensional arrays, only arrays of arbitrary type (which
might be an array or an array of arrays, etc.). The JLS (or was it the
tutorial - which contains just as many flaws as the JLS?) makes mention of
"multi-dimensional arrays in Java" - the truth is, they simply don't exist.

Hope this makes sense.
 
C

Chris Smith

Tony Morris said:
"two-dimensional array is really nothing but an array whose elements are
arrays."

This is the part that is not true.
A two-dimensional array is certainly not an array of arrays and vice versa.
They are not synonymous; the only real relationship is that one may
conceptualise each in a similiar fashion.

The actual quote above is "Remember that a so-called 'two-dimensional
array' is really nothing but an array whose elements are arrays." I'm
not sure why you misquoted it above, but if you missed the first part of
the sentence, that explains the confusion.

In other words, I said that what Jeff was calling a two-dimensional
array is, in reality, an array whose elements are arrays. How did I
know what Jeff meant by saying two-dimensional arrays? Because we're in
a Java newsgroup, and there are no true two-dimensional arrays in Java.
Unless the conversation spans several languages, the phrase "two-
dimensional array" is perfectly clear.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top