ArrayList: toArray(T[] a) : ArrayList : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.util   » [  ArrayList  ]   
 



ArrayList: toArray(T[] a)

/**
 *Output: 
Contents of al: [1, 2, 3, 4]
Sum is: 10 */

import java.util.ArrayList;

public class MainClass {
  public static void main(String args[]) {

    ArrayList<Integer> al = new ArrayList<Integer>();


    al.add(1);
    al.add(2);
    al.add(3);
    al.add(4);

    System.out.println("Contents of al: " + al);

    Integer ia[] new Integer[al.size()];
    ia = al.toArray(ia);

    int sum = 0;

    for (int i : ia)
      sum += i;

    System.out.println("Sum is: " + sum);
  }
}

           
       
Related examples in the same category
1.  new ArrayList < E > ()
2.  ArrayList: add(E o)
3.  ArrayList: add(int index, E element)
4.  ArrayList: contains(Object elem)
5.  ArrayList: ensureCapacity(int minCapacity)
6.  ArrayList: indexOf(Object elem)
7.  ArrayList: iterator()
8.  ArrayList: listIterator()
9.  ArrayList: remove(int index)
10.  ArrayList: remove(Object o)
11.  ArrayList: retainAll(Collection c)
12.  ArrayList: size()
13.  AbstractList: subList(int fromIndex, int toIndex)
14.  ArrayList: trimToSize()
15.  for each loop for ArrayList
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.