KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > util > List

java.util
Interface List<E>

All Superinterfaces:
Collection<E>, Iterable<E>
All Known Implementing Classes:
AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector
See Also:
Top Examples, Source Code, Set, Arrays.asList(Object[]), Collections.nCopies(int, Object), Collections.EMPTY_LIST

boolean add(E o)
See Also:
IllegalArgumentException, NullPointerException, ClassCastException, UnsupportedOperationException, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1545]New and old way of creating a list
By Anonymous on 2005/09/25 18:24:01  Rate
//Old Way 
 myList.add ( "hello" ) ; 
 myList.add ( "goodbye" ) ; 
  
  
 // myList.add ( new Date (  )  ) ; This would compile but cause failures later 
  
  
 Iterator it = myList.iterator (  ) ; 
 while  ( it.hasNext (  )  )   {  
     String s =  ( String ) it.next (  ) ; 
     System.out.println ( s ) ; 
  }  
  
  
  
 //J2SE 1.5 way 
 List < String >  myList = new ArrayList < String >  (  ) ; 
 myList.add ( "hello" ) ; 
 myList.add ( "goodbye" ) ; 
  
  
 // myList.add ( new Date (  )  ) ; This won't compile! 
  
  
 Iterator < String >  it = myList.iterator (  ) ; 
 while  ( it.hasNext (  )  )   {  
     String s = it.next (  ) ;  // Look Ma, no downcast! 
     System.out.println ( s ) ; 
  }  
    
 


[1723]Iterate a String collection
By Anonymous on 2006/03/14 08:55:53  Rate
// iterate a Collection 
 for ( String current : myList )   {  
     System.out.println ( current ) ; 
  }  
 


void add(int index,
         E element)
See Also:
IndexOutOfBoundsException, IllegalArgumentException, NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void add(int index,
                Object element)
See Also:
IndexOutOfBoundsException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[211]Convert list to string array
By Anonymous on 2005/07/19 21:28:38  Rate
//change List to String [  ]  
  
  
 List l; // your linked list  
 String [  ]  items =  ( String [  ]  ) l.toArray ( new String [ 0 ]  ) ; 
  
  
 //add


[1132]_
By pete on 2004/11/21 02:46:25  Rate
List values = new ArrayList (  ) ; 
  
  
     values.add ( new ValueBean ( "True","true" )  ) ; 
     values.add ( new ValueBean ( "False","false" )  ) ; 
     values.add ( new ValueBean ( "Yes","yes" )  ) ;


public boolean add(Object o)
See Also:
IllegalArgumentException, ClassCastException, UnsupportedOperationException, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean addAll(int index,
               Collection<? extends E> c)
See Also:
IndexOutOfBoundsException, IllegalArgumentException, NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean addAll(Collection<? extends E> c)
See Also:
add(Object), IllegalArgumentException, NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void clear()
See Also:
UnsupportedOperationException, E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean contains(Object o)
See Also:
NullPointerException, ClassCastException, E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1370]_
By Anonymous on 2005/06/15 19:55:22  Rate
public boolean hasElement ( int element )   {  
  
  
         if  ( element  <  smallest || element  >  largest )   {  
             return false; 
          }  // if. 
         
          
         return theSet.contains ( new Integer ( element )  ) ; 
          
          
      }  // hasElement.


boolean containsAll(Collection<?> c)
See Also:
contains(Object), NullPointerException, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean equals(Object o)
See Also:
Hashtable, Object.hashCode(), E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


E get(int index)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int hashCode()
See Also:
equals(Object), Object.equals(Object), Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int indexOf(Object o)
See Also:
NullPointerException, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isEmpty()
See Also:
E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


Iterator<E> iterator()
See Also:
Iterable, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[369]List Of JDOM Elements
By somename { at } eyal-sion { dot } com on 2004/02/12 00:57:17  Rate
List all_dates = root.getChildren ( "date" ) ; //List Of  < date >  JDOM Elements 
     Iterator iterator = all_dates.iterator (  ) ; //Geting iterator 
     while  ( iterator.hasNext (  )  )   {  
       Element child =  ( Element )  iterator.next (  ) ; 
       // change / add / erase elements 
      } 


[883]Jaxen compare
By Steve_Begelman { at } Yahoo { dot } com on 2005/02/05 07:29:00  Rate
public  static void JaxenCompare  ( String theUrl, String theXPath )  
  {  
         try 
          {  
             Document doc = new Document ( new File ( theUrl )  ) ; 
              
             XPath xpath = new ElectricXPath ( theXPath  ) ; 
  
  
             List results = xpath.selectNodes (  doc  ) ; 
              
             Iterator resultIter = results.iterator (  ) ; 
              
             int Match = 1; 
  
  
             System.out.println ( "Document :: " + theUrl  ) ; 
             System.out.println ( " XPath :: " + theXPath + "\n" ) ; 
             System.out.println ( "" ) ; 
             System.out.println ( "Results"  ) ; 
             System.out.println ( "----------------------------------" ) ; 
  
  
             while  (  resultIter.hasNext (  )   )  
              {  
               if  (  ( boolean ) resultIter.hasNext (  )  )   {  
                  
                   System.out.println (  resultIter.next (  )   ) ;    
                   System.out.println ( "Matches : " + Match  ) ; 
                   Match++; 
            }  
           else 
             System.out.println ( "No Match on " + theUrl   ) ; 
              }          
              
          }  
         catch  ( ParseException e )  
          {  
             e.printStackTrace (  ) ; 
          }  
          
         catch  ( XPathSyntaxException e )  
          {  
             System.err.println (  e.getMultilineMessage (  )   ) ; 
          }  
          
         catch  ( JaxenException e )  
          {  
             e.printStackTrace (  ) ; 
          }  
          
         catch  ( Exception e )  
          {  
             e.printStackTrace (  ) ; 
          }  
          
  } 


[1499]_
By RuGI on 2005/07/29 17:33:08  Rate
en muchos libros se menciona que es mucho mas eficiente ocupar los Iterators.

int lastIndexOf(Object o)
See Also:
NullPointerException, ClassCastException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


ListIterator<E> listIterator()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


ListIterator<E> listIterator(int index)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


E remove(int index)
See Also:
IndexOutOfBoundsException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean remove(Object o)
See Also:
UnsupportedOperationException, NullPointerException, ClassCastException, E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean removeAll(Collection<?> c)
See Also:
contains(Object), remove(Object), NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean retainAll(Collection<?> c)
See Also:
contains(Object), remove(Object), NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


E set(int index,
      E element)
See Also:
IndexOutOfBoundsException, IllegalArgumentException, NullPointerException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object set(int index,
                  Object element)
See Also:
IndexOutOfBoundsException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int size()
See Also:
E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[592]Get all items in a list
By tuniki { at } yahoo { dot } com on 2005/04/06 12:24:25  Rate
List list= //some objects added 
 for ( int i= 0, j= list.size (  ) ; i  <  j; ++i )  
  {  
   Object obj= list.get ( i ) ; 
  }  
 


List<E> subList(int fromIndex,
                int toIndex)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


Object[] toArray()
See Also:
Arrays.asList(Object[]), E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1382]Copy all the list objects into the array
By Suzanna Diebes on 2005/07/07 11:19:54  Rate
// Create a list 
 List alist = new ArrayList (  ) ; 
 ... populate the list with objects 
  
  
 // Create an array the same size as the list - assuming in this  
 // example that the list contains String objects 
 String [  ]  sarr = new String [ alist.size (  )  ] ; 
  
  
 // Copy all the list objects into the array 
 alist.toArray ( sarr ) ;


public Object[] toArray(Object[] a)
See Also:
ArrayStoreException, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


<T> T[] toArray(T[] a)
See Also:
NullPointerException, ArrayStoreException, E, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags