Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# equality of two arrays

zoyu mi
Greenhorn
Posts: 3

public class Stat {
private double [] data;
public Stat()
{

data [0] = 0.0;

}
public Stat(double[] d)
{
int lengthOfArgument = d.length;
data = new double [lengthOfArgument];
for (int i= 0; i<lengthOfArgument; i++)
{
data [i] = d[i];
}
}
public void setData(double[] d)
{
for (int i= 0; i<d.length; i++)
{
data [i] = d[i];
}
}
public double[] getData()
{
int lengthOfArray= data.length;
double [] temp = new double[lengthOfArray];
for(int i = 0; i< lengthOfArray; i++)
{
temp[i] = data[i];
}
return temp;
}

So I'm using a public static boolean equals( Class s)
{
}
and compare Stat s to an array of type double.
do I use new double s2 =s? to create an array and then compare the values of the arrays? but the problem arises when I compare the lengths of the array.

Mansukhdeep Thind
Ranch Hand
Posts: 1158
Welcome to the ranch Zoyu.

Few pointers on how to use this forum to your best advantage. First off, always use code tags when pasting code:

The code becomes far more readable. Doesn't it?

Next, describe your use case in detail i.e. what is your objective. Then narrow down to what is problem that you are facing doing that.You may get a better and quicker reply. What are you trying to achieve here anyways? Are you trying to write a method that compares 2 arrays to check if they are equal or not?

Campbell Ritchie
Sheriff
Posts: 50714
83
Welcome again

I can see several problems. What happens when you try this?

zoyu mi
Greenhorn
Posts: 3
Mansukhdeep Thind wrote:Welcome to the ranch Zoyu.

Few pointers on how to use this forum to your best advantage. First off, always use code tags when pasting code:

The code becomes far more readable. Doesn't it?

Next, describe your use case in detail i.e. what is your objective. Then narrow down to what is problem that you are facing doing that.You may get a better and quicker reply. What are you trying to achieve here anyways? Are you trying to write a method that compares 2 arrays to check if they are equal or not?

Yes. But I am confused on how java interprets the new object ''s'' and then compare it to an existing array stored beforehand. Do I have to assign s to a new temporary array to be able to check their lengths?

Campbell Ritchie
Sheriff
Posts: 50714
83
Please only quote part of an old post which you are specifically replying to, otherwise the posts simply get longer and longer.

Where is that object s? MT did not say anything about s. I might have, but my s was not an array. It was a Stat object. I was trying to demonstrate something which I thought was going to go wrong. What happened when you tried that code (assuming you found my mistake and corrected it: hint: { should have been (    ? What sort of errors did you suffer?