0

EDIT:-

How can I enable any Collection or Array to hold values from rowValue which is of double type so that values can be displayed on the browser.

public  double[] FindClosestToMultiplesOfTen() {
double rowValue;       
 double []arr=new double[22];
     int i=0;
     try
        {  
       con = getConnection();
          stmt = con.createStatement();
          String sql="some query";
       stmt.executeQuery(sql);
       rs = stmt.getResultSet();
     
       while(rs.next()) 
        {
           for(int j=0; j<1; j++)
             {
               vals[i]  = rs.getDouble(2);
             }
            i++;
         }
        }
     catch( Exception e )
        {
            System.out.println("\nException "+e);
        }
   
    double max = Double.MIN_VALUE;
    for (double v : vals) max = Math.max(max, v);
    int bucketCount = 1 + (int)(max/10);
    double[][] buckets = new double[bucketCount][3];
    for (int i1 = 0; i1 < bucketCount; i1++){
      
        buckets[i1][0] = Double.MAX_VALUE;
    }

    //  iterate the rows
    for (int i1 = 0; i1 < vals.length; i1++)
    {
        double v = vals[i1];
       double mult = getMultipleOfTen(v);
       double delta = Math.abs(mult - v);
       int bIdx = (int)(mult / 10d);
       if (buckets[bIdx][0] > delta)
        {
          buckets[bIdx][0] = delta;
            buckets[bIdx][1] = i1;
            buckets[bIdx][2] = v;
        }
    }

    for (int i1 =1; i1 < buckets.length; i1++)
    {
        double[] bucket = buckets[i1];
        rowValue = bucket[2];
        System.out.println(rowValue);
    }
   return rowValue ;
}

I want to convert rowValue into an array ,so that I can display its values in browser. Currently only last value of rowValue is being displayed as I have taken it as a double type variable. I tried in this way

 for (int i1 =1; i1 < buckets.length; i1++)
    {
        bucket = buckets[i1];
      
        System.out.println(bucket);
        
    }
return bucket;

But when I run this code then in-spite of bucket values,I get values of @ form.How to resolve it?

[D@1108727

[D@191e4c

[D@11415c8

[D@1a220e6 -----

Community
  • 1
  • 1
MES
  • 132
  • 1
  • 14
  • `Arrays.toString(double [] arr)`. That or, just write a nested loop if you need to display it in certain format.. – nhahtdh Jan 28 '15 at 05:51
  • You get the one-dimensional array reference – Juned Ahsan Jan 28 '15 at 05:51
  • 1
    possible duplicate of [Java : how to convert int array to String with toString method](http://stackoverflow.com/questions/10904911/java-how-to-convert-int-array-to-string-with-tostring-method) – user253751 Jan 28 '15 at 05:53
  • @immibis ,here I'm trying to convert double into array and there its convert array into string .Both are different I think. – MES Jan 28 '15 at 06:06
  • @MES "How do I convert a double into an array" doesn't even make sense... It's like asking "How do I convert a parking space into a carpark?" I'm sure you're trying to do something sensible, but I don't know what it is (and neither do other people, judging by the responses) – user253751 Jan 28 '15 at 06:07
  • My actual problem is sum thing else.I wanted to print the rowValues into browser in a tabular format and for that I need a collection or array which can hold all the values of rowValue.But I'm not getting the actual way to do that. – MES Jan 28 '15 at 06:08
  • @ajb sometimes someone posts a comment that's so irrelevant I wish I could downvote it. This is one of those times. – user253751 Jan 28 '15 at 06:10

1 Answers1

0

Java arrays don't override toString(), so you're getting the default toString() from Object. You could use Arrays.toString(double[]) like

// System.out.println(bucket);
System.out.println(Arrays.toString(bucket));

You might also print all of the buckets at once with Arrays.deepToString(Object[]) like

System.out.println(Arrays.deepToString(buckets));
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • yes now values are shown but it is not what I wanted ,the values displayed is **[0.020000457763671875, 8.0, 20.020000457763672]** and what I wanted is **20.02**, **30.01**, **39.99**, The loop which I applied for buckets is wrong I think. – MES Jan 28 '15 at 06:03