Reputation: 107
I made a 2D array with the plans of using it as a table of doubles that interact with each other in different ways. The problem I have come across is that [0,0] is not needed ([x,0] in the table is the numbers that the Y axis represents and [0,x] is the numbers that the X axis represents)
What I am hoping to achieve is to somehow change [0,0] so that it will either be a String to describe the table I'm printing out or to leave it blank, rather than 0 if left null or otherwise inputted. I've tried using a simple method bringing in the double and checking if it's some chosen number unlikely to be calculated within the table and outputting it as a String, but I'm obviously running into the wall of incompatible types (required String, found double)
Upvotes: 1
Views: 47
Reputation: 51445
You can't store a String in a double.
What you can do is create a class that holds a string and your double array.
public class NamedArray {
private String description;
private double[][] array;
}
You can fill in the getters, setters, and constructors.
Edited to add: I just noticed you're wasting most of the space in your double array.
You can use a List of java.awt.Point instances to represent a series of x and y coordinates. Something like this:
List<ChartValue> array;
public class ChartValue {
double value;
Point location;
}
Upvotes: 3