比如现在有一个 List str=new ArrayList();
怎么样把里面的内容写到 aa[]里面去?
怎么样把里面的内容写到 aa[]里面去?
解决方案 »
- 请问,子类可不可以重载父类的鼠标响应事件,请问如何做?
- how to solve the classpath problem?
- Java深入学习:CLASSPATH的简便写法
- 下午要拿去面视了,帮帮忙呀
- 怎样在java类中应用enum枚举类型
- 急求分层窗格JLayeredPane的问题
- applet 中怎么实现ie中的表单递交
- 新手求助,有关对数据库中模糊掉手机号码的程序!!!
- 谁知道Bean中的序列化(implements Serializable)的用处,及如何用?
- 哪位大侠知道Java做3D处理的类库或者资料?
- struts中如何两层遍历ArrayList
- Hashtable的已在元素无法找到的问题
public class T1 {
public static void main(String args[]) {
List<String> l1 = new ArrayList<String>();
l1.add("a");
List<String> l2 = new ArrayList<String>();
l2.add("b");
l1.addAll(l2);
System.out.println(l1);
String[] s=new String[l1.size()];
l1.toArray(s);
System.out.println(Arrays.toString(s));
}
}
str.toArray(new Object[str.size()]);
Object[] aa = str.toArray(new Object[str.size()]);
Object[] o = new Object[ls.size()];
int i = 0;
Iterator iter = ls.iterator();
while(iter.hasNext())
{
o[i] = iter.next();
i++;
}
while(iter.hasNext())
{
o[i] = iter.next();
i++;
我写的时候iter.里没有hasNext和next 要包含什么吗?import java.util.*;这个已经有了
Random rand=new Random();
List stra=new ArrayList();
for(int i=0;i<ff;i++){
int kpoint=60+rand.nextInt(10);
if(!stra.contains(kpoint()){
stra.add(kpoint);
}
else{
i--;
}
}
String[] s=new String[l1.size()];
stra.toArray(s);
写在JSP里面的
最后怎么显示S[]?用
for(int j=0;j<s.length;j++){
out.print(s[j]);
}对不对?
Random rand=new Random();
List stra=new ArrayList();
for(int i=0;i<ff;i++){
int kpoint=60+rand.nextInt(10);
if(!stra.contains(kpoint()){
stra.add(kpoint);
}
else{
i--;
}
}
String[] s=new String[str.size()];
stra.toArray(s);
写在JSP里面的
最后怎么显示S[]?用
for(int j=0;j<s.length;j++){
out.print(s[j]);
}对不对?
上面写错了一点
List stra = new ArrayList();
for (int i = 0; i < 10; i++) {
int kpoint = 60 + rand.nextInt(10);
if (!stra.contains(kpoint)) {
stra.add(kpoint);
} else {
i--;
}
}
Integer[] s = new Integer[stra.size()];
stra.toArray(s);
// 写在JSP里面的
// 最后怎么显示S[]?用
for (int j = 0; j < s.length; j++) {
out.print(s[j]);
}
List stra = new ArrayList();
for (int i = 0; i < 10; i++) {
int kpoint = 60 + rand.nextInt(10);
if (!stra.contains(kpoint)) { //多个"("
stra.add(kpoint);
} else {
i--;
}
}
Integer[] s = new Integer[stra.size()]; //类型不对,List里面存的是int型的,数组也要是int型的。注意:jdk5以上才可以用integer,否则就必须用int
stra.toArray(s);
// 写在JSP里面的
// 最后怎么显示S[]?用
for (int j = 0; j < s.length; j++) {
out.print(s[j]);
}
List stra=new ArrayList();
for (int i=0;i<ff;i++){
int kpoint=60+rand.nextInt(10);
if(!stra.contains(kpoint)){
stra.add(kpoint);
}
else{
i--;
}
}
int[] str=new int[stra.size()];
stra.toArray(str);
for(int j=0;j<str.length;j++){
out.print(str[j]);
}
错误提示:
Generated servlet error:
C:\Documents and Settings\dangkaizhan\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\bysj\org\apache\jsp\autotest_jsp.java:191: 找不到符号
符号: 方法 toArray(int[])
位置: 接口 java.util.List
stra.toArray(str);
^
注意:C:\Documents and Settings\dangkaizhan\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\bysj\org\apache\jsp\autotest_jsp.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。
1 错误
朋友再帮我看看啊...........................
int kpoint=60+rand.nextInt(10);
if(!stra.contains(kpoint)){
stra.add(kpoint);}
else{
i--;
}
}需要修改为: for (int i = 0; i < 0xff; i++) {
int kpoint = 60 + rand.nextInt(10);
Integer kpoObj = new Integer(kpoint);//int-->Integer对象
if (!stra.contains( kpoObj ) ) { //contains()方法需要对象参数
stra.add( kpoObj ); //add()方法需要对象参数 } else {
i--;
}
}(2)源码里的:int[] str=new int[stra.size()];
stra.toArray(str);需要修改为:Integer[] str = new Integer[stra.size()];
stra.toArray(str);//toArray()方法需要对象参数问题在于,List容器中放置的都需要是对象,int只是基本类型,所以List大部分方法的参数需要使用与int相对应的Integer对象(当前情况)才可以,其它不变,再试试吧^_^
真的很感谢你 终于解决了 十分感谢
我给分的时候怎么出现script error 左下脚?
String[str.size()] strs = str.toArray();