比如现在有一个 List str=new ArrayList();
怎么样把里面的内容写到 aa[]里面去?

解决方案 »

  1.   

    import java.util.*;
    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));
    }
    }
      

  2.   

    List str=new ArrayList();
    str.toArray(new Object[str.size()]);
      

  3.   

    List str=new ArrayList();
    Object[] aa = str.toArray(new Object[str.size()]);
      

  4.   

    List ls = new ArrayList();
    Object[] o = new Object[ls.size()];
    int i = 0;

    Iterator iter = ls.iterator();
    while(iter.hasNext())
    {
      o[i] = iter.next();
      i++;
    }
      

  5.   

    str.toArray(aa);需要保证数组aa长度够长,且其声明类型为list中所有类的类型都是这个类型或者其子类型
      

  6.   

    str.toArray(aa);需要保证数组aa长度够长,且list中所有类的类型都是aa声明的类型或者其子类型
      

  7.   

    Iterator iter = ls.iterator();
    while(iter.hasNext())
    {
      o[i] = iter.next();
      i++;
    我写的时候iter.里没有hasNext和next 要包含什么吗?import java.util.*;这个已经有了
      

  8.   

    问题还没解决 回来给分
    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]);
    }对不对?
      

  9.   

    问题还没解决 回来给分
    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]);
    }对不对?
    上面写错了一点
      

  10.   

    Random rand = new Random();
    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]);
    }
      

  11.   

    Random rand = new Random();
    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]);
    }
      

  12.   

    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--;
             }    
        }
        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 错误
    朋友再帮我看看啊...........................
      

  13.   

    如:davidafairy() 所说的:(1)源码里:for (int i=0;i<ff;i++){
    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对象(当前情况)才可以,其它不变,再试试吧^_^
      

  14.   

    hhlong(╰☆〖龙】╮) 
     真的很感谢你 终于解决了 十分感谢
    我给分的时候怎么出现script error 左下脚?
      

  15.   

    List str=new ArrayList();
    String[str.size()] strs = str.toArray();