java技術(shù)博客
jsp博客
BlogJava
首頁(yè)
新隨筆
聯(lián)系
聚合
管理
數(shù)據(jù)加載中……
java中的vector
/** */
/**
*/
/** */
/**
* 我們?cè)O(shè)計(jì)的學(xué)生基本類
*/
class
Student
{
private
String strName
=
""
;
//
學(xué)生姓名
private
String strNumber
=
""
;
//
學(xué)號(hào)
private
String strSex
=
""
;
//
性別
private
String strBirthday
=
""
;
//
出生年月
private
String strSpeciality
=
""
;
//
專業(yè)
private
String strAddress
=
""
;
//
地址
public
Student(String name, String number)
{
strName
=
name;
strNumber
=
number;
}
public
String getStudentName()
{
return
strName;
}
public
String getStudentNumber()
{
return
strNumber;
}
public
void
setStudentSex(String sex)
{
strSex
=
sex;
}
public
String getStudentSex()
{
return
strSex;
}
public
String getStudentBirthday()
{
return
strBirthday;
}
public
void
setStudentBirthday(String birthday)
{
strBirthday
=
birthday;
}
public
String getStudentSpeciality()
{
return
strSpeciality;
}
public
void
setStudentSpeciality(String speciality)
{
strSpeciality
=
speciality;
}
public
String getStudentAddress()
{
return
strAddress;
}
public
void
setStudentAddress(String address)
{
strAddress
=
address;
}
public
String toString()
{
String information
=
"
學(xué)生姓名=
"
+
strName
+
"
, 學(xué)號(hào)=
"
+
strNumber;
if
(
!
strSex.equals(
""
) )
information
+=
"
, 性別=
"
+
strSex;
if
(
!
strBirthday.equals(
""
))
information
+=
"
, 出生年月=
"
+
strBirthday;
if
(
!
strSpeciality.equals(
""
) )
information
+=
"
, 專業(yè)=
"
+
strSpeciality;
if
(
!
strAddress.equals(
""
) )
information
+=
"
, 籍貫=
"
+
strAddress;
return
information;
}
}
/** */
/**
* 通過(guò)這個(gè)程序,測(cè)試Vector的添加元素及插入元素
*/
import
java.util.Vector;
public
class
VectorTest1
{
public
static
void
main(String[] args)
{
Vector vec
=
new
Vector();
Student tom
=
new
Student(
"
Tom
"
,
"
20020410
"
);
Student jack
=
new
Student(
"
Jack
"
,
"
20020411
"
);
Student smith
=
new
Student(
"
Smith
"
,
"
20020412
"
);
vec.add(tom);
vec.add(
0
, jack);
//
插入一個(gè)新的元素
vec.add(
0
, smith);
//
又插入一個(gè)新的元素
for
(
int
i
=
0
; i
<
vec.size(); i
++
)
{
System.out.println(vec.get(i));
}
}
}
/** */
/**
* 通過(guò)這個(gè)程序,測(cè)試Vector的添加元素及插入元素
*/
import
java.util.Vector;
public
class
VectorTest
{
public
static
void
main(String[] args)
{
Vector vec
=
new
Vector();
Student tom
=
new
Student(
"
Tom
"
,
"
20020410
"
);
Student jack
=
new
Student(
"
Jack
"
,
"
20020411
"
);
Student smith
=
new
Student(
"
Smith
"
,
"
20020412
"
);
vec.add(
1
, tom);
for
(
int
i
=
0
; i
<
vec.size(); i
++
)
{
System.out.println(vec.get(i));
}
}
}
/** */
/**
* 通過(guò)這個(gè)程序,測(cè)試Vector的ratainAll方法
*/
import
java.util.Vector;
public
class
VectorTest2
{
public
static
void
main(String[] args)
{
VectorTest2 test
=
new
VectorTest2();
Vector vec1
=
new
Vector();
Vector vec2
=
new
Vector();
Student tom
=
new
Student(
"
Tom
"
,
"
20020410
"
);
Student jack
=
new
Student(
"
Jack
"
,
"
20020411
"
);
Student smith
=
new
Student(
"
Smith
"
,
"
20020412
"
);
Student rose
=
new
Student(
"
Rose
"
,
"
20020413
"
);
vec1.add(tom);
vec1.add(jack);
vec1.add(smith);
vec1.add(rose);
System.out.println(
"
第一個(gè)Vector中的元素分別是:
"
);
test.display(vec1);
vec2.add(rose);
vec2.add(tom);
System.out.println(
"
\n第二個(gè)Vector中的元素分別是:
"
);
test.display(vec2);
System.out.println(
"
\n調(diào)用retainAll方法后,第一個(gè)Vector中的元素分別是:
"
);
vec1.retainAll(vec2);
test.display(vec1);
}
public
void
display(Vector vec)
{
for
(
int
i
=
0
; i
<
vec.size(); i
++
)
{
System.out.println(vec.get(i));
}
}
}
posted on 2008-11-07 16:02
郭興華
閱讀(351)
評(píng)論(0)
編輯
收藏
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
Powered by:
BlogJava
Copyright © 郭興華
<
2008年11月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
統(tǒng)計(jì)
隨筆 - 84
文章 - 1
評(píng)論 - 2
引用 - 0
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(3)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆分類
java每日練習(xí)代碼
(rss)
TESTARRAY(6)
(rss)
事件模型與事件處理
(rss)
隨筆檔案
2009年1月 (2)
2008年11月 (14)
2008年10月 (68)
文章檔案
2008年10月 (1)
搜索
最新評(píng)論
1.?re: jsp讀取*.TXT
請(qǐng)問(wèn) retstr是什么數(shù)據(jù)類型?String?好像不行哦
--jsp
2.?re: StudentTest1.java
看不懂你的意思,代碼沒(méi)有縮進(jìn),看著很不習(xí)慣那。
--楊愛(ài)友
閱讀排行榜
1.?java中的treemap(4606)
2.?JDBC連接SQLSERVER(1824)
3.?判斷一個(gè)一個(gè)路徑是否是目錄(1087)
4.?jsp讀取*.TXT(767)
5.?java代理模式(728)
評(píng)論排行榜
1.?StudentTest1.java(1)
2.?jsp讀取*.TXT(1)
3.?java1.5注解(二)(0)
4.?java1.5注解(一)(0)
5.?jsp中使用類(0)
主站蜘蛛池模板:
武穴市
|
信阳市
|
洛扎县
|
康平县
|
颍上县
|
肥乡县
|
西林县
|
新沂市
|
陆良县
|
阳城县
|
平远县
|
丁青县
|
龙游县
|
宁陕县
|
平泉县
|
寿阳县
|
淳安县
|
永安市
|
保康县
|
平舆县
|
信宜市
|
凉山
|
堆龙德庆县
|
五台县
|
鸡西市
|
泰宁县
|
牙克石市
|
繁峙县
|
萨迦县
|
武冈市
|
侯马市
|
桑日县
|
电白县
|
繁峙县
|
大理市
|
齐齐哈尔市
|
乐陵市
|
望都县
|
太湖县
|
合川市
|
巨鹿县
|