File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes convert Object[] to String[] with null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "convert Object[] to String[] with null values" Watch "convert Object[] to String[] with null values" New topic
Author

convert Object[] to String[] with null values

Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
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

Joined: Mar 12, 2011
Posts: 808
You're going to want to use BigDecimal.ZERO. Object[i] = 0.00 will result in a Double.
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
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

Joined: Dec 29, 2010
Posts: 33
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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: Dec 29, 2010
Posts: 33
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

Joined: Dec 29, 2010
Posts: 33
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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert Object[] to String[] with null values