List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 1, 1.2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
How can I use java code find not integer type(1.2) in x List?
List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 1, 1.2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
How can I use java code find not integer type(1.2) in x List?
Try this:
for (double d : x.get(0)) {
System.out.println("Not Integer:" + ((int) (d * 10) / 10 != d));
}
Update (this should be enough as well):
System.out.println("Not Integer:" + ((int) d != d));
EDIt: I just understood the question. So here is the updated answer
List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 1, 1.2, 2.9, 3.9, 4.1, 5.5, 6, 7, 8, 9, 10, 11, 12 });
List<Double> foundDoubles = new ArrayList<Double>();
int i = 0;
for(double d : x.get(0)) {
i = (int)d;
if(i != d) {
foundDoubles.add(d);
}
}
for(double d : foundDoubles) {
System.out.println(d);
}
}
You can try the following:
for(double i : x) {
String total2 = String.valueOf(i);
if(i.contains(".")){
// ...
}
}
or you can use if(Math.floor(i) > 0)
alter for String
aproarch.
I'm new to Java :P But I think direct comparison wouldn't be good?
double a = 1;
double b = 1;
double c = a-b;
if (Math.abs(c) == 0) {...}
Basically set another primitive to the value your looking for. Subtract that value from the list. If one of the index's contains 1.2 than 1.2-1.2 = 0? Than you know where it is?