JSP中的数组怎样定义?

loes 2002-05-13 06:44:46
能用:String[] group;
int i=0;
while(Rs.next()){
group[i]=Rs.getString("key");
i++;}
for(inti=0;i<group.length;i++){
out.print(group[i]);}
还有:数组怎样和其他值比较?如写:
for(int j=0;j<group.length;j++){
if(group[i].equals("111")){
out.print("pppp");}
}这样程序就出错了,我不知道该怎样写?请教各位大虾,谢谢
...全文
1969 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andrawu 2002-05-14
  • 打赏
  • 举报
回复
怎么会呢???
你仔细查查。
loes 2002-05-14
  • 打赏
  • 举报
回复
在程序
int gLen = group.size();
for(int i=0;i<gLen;i++){
sStr = group.elementAt(i).toString() ;
out.print(sStr) ;
if(sStr.equals("111")){
out.print("pppp");
}
}
中,sStr.equals("111"))不知为什么不起作用;如果sStr=222依然会打印出pppp,为什么?
xineryixin 2002-05-14
  • 打赏
  • 举报
回复
java.util.*
loes 2002-05-14
  • 打赏
  • 举报
回复
用Vector需要引入什么类吗?直接用好象不行
loes 2002-05-14
  • 打赏
  • 举报
回复

if(group[i].equals("111"))不能比较,出现java.lang.NullPointerException错误,为什么?
js_ning_cn 2002-05-13
  • 打赏
  • 举报
回复
String[] group;
int i=0;
while(Rs.next()){
group[i]=Rs.getString("key");
i++;}
for(inti=0;i<group.length;i++){
out.print(group[i]);}

定义数组
int str[] = new int[20];
然后将数组初始化
for (short i=0 ;i<12;i++)
{
str[[i]=i;
}
然后按照你的程序 ,你的错误就可以解决了



Andrawu 2002-05-13
  • 打赏
  • 举报
回复
对于开始不知道长度的数组,可以用Vector,还可能ArrayList、Hashtable、Map、HashMap等。
下面是用Vector的例子,你试试。
Vector group = new Vector();
String sStr = "" ;
while(Rs.next()){
group.add(Rs.getString("key"));
}
int gLen = group.size();
for(int i=0;i<gLen;i++){
sStr = group.elementAt(i).toString() ;
out.print(sStr) ;
if(sStr.equals("111")){
out.print("pppp");
}
}
Andrawu 2002-05-13
  • 打赏
  • 举报
回复
你的数组没有定义长度,是不行的。
你的数组其他值比较没有错。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧