SafeVectorCopy.java
资源名称:Source.rar [点击查看]
上传用户:songled
上传日期:2022-07-14
资源大小:94k
文件大小:1k
源码类别:
进程与线程
开发平台:
Java
- import java.util.*;
- public class SafeVectorCopy extends Object {
- public static void main(String[] args) {
- Vector vect = new Vector();
- vect.addElement("Synchronization");
- vect.addElement("is");
- vect.addElement("important");
- String[] word;
- synchronized ( vect ) {
- int size = vect.size();
- word = new String[size];
- for ( int i = 0; i < word.length; i++ ) {
- word[i] = (String) vect.elementAt(i);
- }
- }
- System.out.println("word.length=" + word.length);
- for ( int i = 0; i < word.length; i++ ) {
- System.out.println("word[" + i + "]=" + word[i]);
- }
- }
- }