java.util.ArrayList

   數(shù)組和數(shù)組列表之間有著重大的區(qū)別。數(shù)組是 Java 語(yǔ)言的一個(gè)特征,對(duì)于每個(gè)元素類(lèi)型 T ,都有數(shù)組類(lèi)型 T[]; 然而, ArrayList 類(lèi)是個(gè)定義 java.util 包中的類(lèi)庫(kù)。這是一個(gè)存放 object 類(lèi)型元素的 " 普通性 " 的類(lèi)型。要注意的是,要從數(shù)組列表中提取元素時(shí),需要進(jìn)行類(lèi)型轉(zhuǎn)換。
 
使用 add 方法可以向數(shù)組列表中添加新元素:
   ArrayList staff = new ArrayList();
   staff.add(new Employee(....));
   staff.add(new Employee(....));
   ArrayList
類(lèi)管理了一個(gè) Object 引用的內(nèi)部數(shù)組。最終,可能會(huì)用完數(shù)組的空間。如果調(diào)用了 add ,而內(nèi)部數(shù)組已經(jīng)滿(mǎn)了,數(shù)組列表將自動(dòng)創(chuàng)建了一個(gè)更大的數(shù)組,并自動(dòng)把小數(shù)組中的對(duì)象拷貝到大數(shù)組中
  Size
方法返回?cái)?shù)組列表的實(shí)際元素個(gè)數(shù)
    staff.size()   
它等價(jià)于數(shù)組 a a.length   
   
訪(fǎng)問(wèn)數(shù)組列表元素
因?yàn)?/span> ArrayList 類(lèi)不是 Java 語(yǔ)言的一部分,它只是個(gè)提供在標(biāo)準(zhǔn)庫(kù)中、由某人編寫(xiě)的工具類(lèi),并不像在訪(fǎng)問(wèn)數(shù)組元素時(shí)可以使用 [] 語(yǔ)法那

樣,要存取或改變數(shù)組元素,你必須使用 get set 方法
  
要設(shè)置第 i 個(gè)元素,需要使用:
   staff.set(i,harry);
得到數(shù)組列表元素要更復(fù)雜一些,因?yàn)?/span> get 方法返回的類(lèi)型是 Object ,你還需要把它轉(zhuǎn)換為想要的類(lèi)型
   Employee e = (Employee)staff.get(i);
它等價(jià)于 Employee e = a[i];

  
最后總結(jié)一下:
 
無(wú)需指定數(shù)組大小
add 增添任意多的元素 ;
size() 代替 length 計(jì)算元素的個(gè)數(shù) ;
(Employee)a.get(i) 代替 a[i] 訪(fǎng)問(wèn)元素 i;

public  Collection setRollBack(QueueVB job)  throws  CustomException
    
{
        
        String sqlselect 
=   " select FileName from JobQueue where BatchNum= " + job.getBatchNum() + "  and DocTypeID= " + job.getDocTypeID() + " and JobState='6' " ;
        String sql 
=   " update JobQueue set JobState= " + JobState.SAVE + "  where BatchNum= " + job.getBatchNum() + "  and DocTypeID= " + job.getDocTypeID() + "  and JobNum= " + job.getJobNum() + "" ;
        
ArrayList array = new  ArrayList();
        System.out.println(sql);
                
try
                
{
                    getConnection
= ConnectionLocator.getInstance().getConnection(strJNDI);
                    ResultSet rs
= null ;
                    
if (getConnection != null )
                    
{
                        PreparedStatement pstmt1
= getConnection.prepareStatement(sqlselect);
                        PreparedStatement pstmt
= getConnection.prepareStatement(sql);
                        
                        rs 
=  pstmt1.executeQuery();
                        pstmt.executeUpdate();
                        
while (rs.next())
                        
{
                           
 String fileName  =  rs.getString( " FileName " );
                            FileNameVB filenameVB 
=   new  FileNameVB();// 將得到的 文件名 進(jìn)行封裝
                            filenameVB.setFileName(fileName);
                            array.add(filenameVB);
                        }
                        
try
                        
{
                            pstmt.close();
                        }

                        
catch (SQLException e)
                        
{ throw   new  CustomException(e.getMessage(), " exs " );}
                        
try
                        
{
                            getConnection.close();
                        }

                        
catch (SQLException e)
                        
{ throw   new  CustomException(e.getMessage(), " exs " );}
                    }

                }

                
catch (SQLException e)
                
{ throw   new  CustomException(e.getMessage(), " ex00050 " );}
                
return  array;
    }

讀取 arraylist 里的值

Collection m  = inputFacade.setRollBack(job);
                    ArrayList array = (ArrayList)m;
                    
for ( int  i=0;i<array.size();i++)
                    
{   
                        filenameVB = (FileNameVB)array.get(i);
                           }