aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays.asList(Object[] o) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays.asList(Object[] o)" Watch "Arrays.asList(Object[] o)" New topic
Author

Arrays.asList(Object[] o)

michael huang
Ranch Hand

Joined: Jul 30, 2000
Posts: 63
hi, guys
when i read TIJ2 about unsupported operation, it has code like this:
String[] s={...};
List a= Arrays.asList(s);
and i look the source of jdk,
public static List asList(Object[] a) {
return new ArrayList(a);
}
so i look at the ArrayList's constructor, there is no any constructor accept array as prarameter, neither it's ancestor.
so how does List produced? can anyone explain for me?
thanks
michael
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Michael,
I can't answer your question but I'm really curious How did you look at the source for the JDK class??
Thanks
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
ali farid
Ranch Hand

Joined: Aug 26, 2000
Posts: 60
Hi michael
I think you have been looking for the constructor in the java.util.ArrayList's java file.
if you look into java.util.Arrays java file then you can find an inner class "ArrayList" at the end just below the asList() method, which contains the constructor which takes the array as parameter.
the inner class which i copied from Arrays is as:
private static class ArrayList extends AbstractList
implements java.io.Serializable
{
private Object[] a;
ArrayList(Object[] array) {
a = array;
}
public int size() {
return a.length;
}
public Object[] toArray() {
return (Object[]) a.clone();
}
public Object get(int index) {
return a[index];
}
public Object set(int index, Object element) {
Object oldValue = a[index];
a[index] = element;
return oldValue;
}
}
michael huang
Ranch Hand

Joined: Jul 30, 2000
Posts: 63
hi, ali
oh, yes, thank you very much, i just look at the file java.util.ArrayList, and not find the inner class arraylist at Arrays.
and Just because of this class, so there are many "unsupported operation".
BTW Jane, you can extract java source at jkd directory using: jar -xvf src.jar.
thank you
michael
[This message has been edited by michael huang (edited October 20, 2000).]
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Thanks Michael.
------------------
Jane
 
Don't get me started about those stupid light bulbs.
 
subject: Arrays.asList(Object[] o)
 
Similar Threads
Using asList with Generics
Question of Arrays.asList()
Immodifable List
why the list size is 1
How to display values in an array