• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

convert Object[] to String[] with null values

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am attempting to convert an Object[] to String[] using this code

The problem is when the Object[] contains null values I need them to copied over and make sure the populated values maintain their place in the array. All of the values that could possibly return null are BigDecimal Type longs with 2 decimal places. They could be defaulted to 0.00 If I had to. Can I add something to my For loop to allow for this, something along the lines of...

???

Thanks in advance,
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going to want to use BigDecimal.ZERO. Object[i] = 0.00 will result in a Double.
 
Brennen smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Now to clarify your saying instead of
Object[i] = 0.00;
use
Object[i] = BigDecimal.ZERO; This gives me an error Incompatible types String to BigDecimal.
 
Brennen smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ignore me I figured it out...



But i am encountering an issue with my if then statement



I also tried

What is the proper way to check my Object[i].
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I ask why you're converting all that data to String? You're throwing away information when you do that.
 
Brennen smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to make it short... I am returning 15 columns of data from a SQL query I only want to display the first 4 rows but still retain the information to the initial 15 returned. Once I set the result to my TabelModel the remaining rows are lost. Heres the method...
 
Brennen smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok well I figured it out. I remembered that the equals() method checks for value equality, that it compares the contents of two objects. And because null is not an object it was throwing an error. I have replaced it with..


which works correctly.
Thanks again guys,
reply
    Bookmark Topic Watch Topic
  • New Topic