Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Programmer Certification (OCPJP)
Conversion of reference values
Nitasha Gupta
Greenhorn
Posts: 14
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Object [] objArray =new Object[3];
int[] intArray =new int[10];
objArray=intArray; //Compile time error
Is there anyway to convert int[] to Object[] type?
Keith Lynn
Ranch Hand
Posts: 2412
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No, Object[] and int[] are different types. You would have to step through the Object array and somehow convert each one into an int and then store them in the corresponding position in the int array.
Peter MacMillan
Ranch Hand
Posts: 34
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class IntTest { public static void main(String[] args) { Object[] things; int[] numbers = new int[10]; for (int i = 0; i < 10; ++i) { numbers[i] = i; } things = new Integer[numbers.length]; for (int i = 0; i < numbers.length; ++i) { things[i] = numbers[i]; //nb } } }
note at //nb under versions prior to jdk 1.5, you'd have to do:
things[i] = new Integer(numbers[i]);
I'm not aware of an API feature that can do this.
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Which class represents array in java?
Array of Objects
Object Reference Conversion
References
Primitive arrays
More...