aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Conversion toArray and asList problem" Watch "Conversion toArray and asList problem" New topic
Author

Conversion toArray and asList problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634




Queries

1.The output of line 23-24 is
[[I@3e25a5]

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

2.The output of line 27-29 is

[[I@3e25a5]

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: 438

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%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
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: http://aspose.com/file-tools
 
subject: Conversion toArray and asList problem
 
Similar Threads
Class cast
Using Lists and converting them to arrays problem
Integer
Discussing errata for K&B, SCJP 6
Usage of indexOf method of ArrayList class