crowd.java
来自「非常好的java事例以及带源码事例的java2教程」· Java 代码 · 共 49 行
JAVA
49 行
import java.util.*;
class Crowd
{
// Constructors
public Crowd()
{
// Create default Vector object to hold people
people = new Vector();
}
public Crowd(int numPersons)
{
// Create Vector object to hold people with given capacity
people = new Vector(numPersons);
}
// Sort the people
public void sort()
{
Collections.sort(people); // Use the static sort method
}
// Add a person to the crowd
public boolean add(Person someone)
{
return people.add(someone); // Use the Vector method to add
}
// Get the person at a given index
Person get(int index)
{ return (Person)people.get(index); }
// Get number of persons in crowd
public int size()
{ return people.size(); }
// Get people store capacity
public int capacity()
{ return people.capacity(); }
// Get an iterator for the crowd
public Iterator iterator()
{ return people.iterator(); }
// Person store - only accessible through methods of this class
private Vector people;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?