• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays.asList(Object[] o)

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael.
------------------
Jane
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic