File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Conversion toArray and asList problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Conversion toArray and asList problem" Watch "Conversion toArray and asList problem" New topic

Conversion toArray and asList problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634


1.The output of line 23-24 is

shouldn't it be 3,5,76,8,5,345436 ?

2.The output of line 27-29 is


why i am getting this ambiguous output ?
how to get the content of object array ob ?

3.In the lines 43-47
the array dimension is 0 still the array named incompletearray prints the data contained in the list ab
can anyone tell me how this possible ?

4. The code of lines 50-53 is commented.

when i put the commented code,i get this error java uses unchecked or unsafe operations.

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446

You know that the abws is a list and actually it is an object isn't it?
like arrays... lists are also objects in java
so when you just print the abws variable, it gives the hashcode of the object at which it is resting
you should not expect the list to output
when you print the array variable using System.out.println(abs);
then also you will get the same output
this is also because of the same reason that array is an object in java and printing it will print the hashcode

also you are getting the same output because whenever you modify the arrays or the lists using toArray or asList methods
then the changes are done directly in the original array or the list... the copy of the list is not created
hence the changes done int array or the list are reflected in both

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

@ mohitkumar gupta...

Your problem is related with Non - generics collection. A non - generics collection is quite happy to hold anything that is NOT a primitive. Use a Integer array instead of int array.

If I correct it,

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
I agree. Here's the link:
subject: Conversion toArray and asList problem
It's not a secret anymore!