Vector 应用实例
2010-08-20 15:27
260 查看
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
public class TestVector {
public static void printElement(Collection<?> c)
{
Iterator<?> it = c.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
public static void main(String[] args) {
Vector<Student> transcript = new Vector<Student>();
transcript.addElement(new Student("Lihua",1,83));
transcript.addElement(new Student("Lilei",2,78));
transcript.addElement(new Student("Hanmeimei",3,90));
System.out.println(transcript.size());
transcript.insertElementAt(new Student("Wangping",4,78),1);
printElement(transcript);
Student s = (Student)transcript.elementAt(0);
System.out.println(s.toString());
}//end of main
}// end of TestVector
class Student{
private String sName;
private int sID;
private double sScore;
public Student(String sName, int sID, double sScore)
{
this.sName = sName;
this.sID = sID;
this.sScore = sScore;
}
public String getsName()
{
return this.sName;
}
public double getsScore()
{
return this.sScore;
}
public String toString()
{
return "NO." + this.sID + ":" + this.sName + "," +this.sScore;
}
}
返回结果:
3
NO.1:Lihua,83.0
NO.4:Wangping,78.0
NO.2:Lilei,78.0
NO.3:Hanmeimei,90.0
NO.1:Lihua,83.0
import java.util.Iterator;
import java.util.Vector;
public class TestVector {
public static void printElement(Collection<?> c)
{
Iterator<?> it = c.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
public static void main(String[] args) {
Vector<Student> transcript = new Vector<Student>();
transcript.addElement(new Student("Lihua",1,83));
transcript.addElement(new Student("Lilei",2,78));
transcript.addElement(new Student("Hanmeimei",3,90));
System.out.println(transcript.size());
transcript.insertElementAt(new Student("Wangping",4,78),1);
printElement(transcript);
Student s = (Student)transcript.elementAt(0);
System.out.println(s.toString());
}//end of main
}// end of TestVector
class Student{
private String sName;
private int sID;
private double sScore;
public Student(String sName, int sID, double sScore)
{
this.sName = sName;
this.sID = sID;
this.sScore = sScore;
}
public String getsName()
{
return this.sName;
}
public double getsScore()
{
return this.sScore;
}
public String toString()
{
return "NO." + this.sID + ":" + this.sName + "," +this.sScore;
}
}
返回结果:
3
NO.1:Lihua,83.0
NO.4:Wangping,78.0
NO.2:Lilei,78.0
NO.3:Hanmeimei,90.0
NO.1:Lihua,83.0
相关文章推荐
- Iterator&Vector应用实例
- Java集合——Stack和Vector应用实例
- Iterator&Vector应用实例
- Iterator&Vector应用实例
- Iterator&Vector应用实例
- Symfony 模版快捷变量应用实例
- if与while在脚本编程中的应用与实例
- C语言库函数大全及应用实例五
- 一些SQL Server的应用实例
- Java 方法应用实例01
- Javascript中的e.keyCode大全及实例应用
- Cloud Foundry中应用实例生命周期过程中的文件目录分析
- C++中引用(&)的用法和应用实例
- Webcollector + Spring + MVC 搭建应用初探(五)(Crab 推荐系统实例)
- 实例详解CSS的继承性及其应用
- 数据库设计三大范式应用实例剖析
- encache整合spring应用实例
- PX4应用实例3:px4_simple_app
- VS2010中水晶报表安装应用及实例
- Nabou应用实例