Monday, 5 November 2007

List example

import java.util.List ;
import java.util.Vector ;

public class A {

public static void main(String[] args) {
A a = new A() ;
List b = a.getSchools() ;

// get values
for( int i = 0 ; i < b.size() ; i++ ){
String str = (String)b.get(i) ;
System.out.println("["+i+"]:"+str) ;
}

System.out.println("=================================") ;

// add the value as the last position
b.add("SchoolName4") ;
b.add("SchoolName5") ;

// get values
for( int i = 0 ; i < b.size() ; i++ ){
String str = (String)b.get(i) ;
System.out.println("["+i+"]:"+str) ;
}

System.out.println("=================================") ;

// insert value to 3 position
b.add(2, "SchoolName6") ;

// get values
for( int i = 0 ; i < b.size() ; i++ ){
String str = (String)b.get(i) ;
System.out.println("["+i+"]:"+str) ;
}


}

private List getSchools() {

Vector v = new Vector() ;
v.add("SchoolName1") ;
v.add("SchoolName2") ;
v.add("SchoolName3") ;
return (List)v ;

}

}

No comments: