• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert Object[] to String[] with null values

 
Brennen smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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,
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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].
 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic