aspose file tools*
The moose likes Beginning Java and the fly likes equality of two arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "equality of two arrays" Watch "equality of two arrays" New topic
Author

equality of two arrays

zoyu mi
Greenhorn

Joined: Mar 29, 2013
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

Joined: Jul 27, 2010
Posts: 1157

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?


~ Mansukh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
Welcome again

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

Joined: Mar 29, 2013
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

Joined: Oct 13, 2005
Posts: 40061
    
  28
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equality of two arrays