• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equality of two arrays

 
zoyu mi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49380
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

I can see several problems. What happens when you try this?
 
zoyu mi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49380
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic