Arrays有这个静态方法么?
你没有NEW吧

解决方案 »

  1.   

    程序,只要看thinking in java 的人都有,我不是自己打的程序,是从BruceEckel.com下载的与书配套的code直接编译。我还配合jcreator用。具体程序我贴出来如下://: c09:FillingArrays.java
    // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    // Using Arrays.fill()
    import com.bruceeckel.util.*;
    import java.util.*;public class FillingArrays {
      public static void main(String[] args) {
        int size = 6;
        // Or get the size from the command line:
        if(args.length != 0)
          size = Integer.parseInt(args[0]);
        boolean[] a1 = new boolean[size];
        byte[] a2 = new byte[size];
        char[] a3 = new char[size];
        short[] a4 = new short[size];
        int[] a5 = new int[size];
        long[] a6 = new long[size];
        float[] a7 = new float[size];
        double[] a8 = new double[size];
        String[] a9 = new String[size];
        Arrays.fill(a1, true);
        Arrays2.print("a1 = ", a1);
        Arrays.fill(a2, (byte)11);
        Arrays2.print("a2 = ", a2);
        Arrays.fill(a3, 'x');
        Arrays2.print("a3 = ", a3);
        Arrays.fill(a4, (short)17);
        Arrays2.print("a4 = ", a4);
        Arrays.fill(a5, 19);
        Arrays2.print("a5 = ", a5);
        Arrays.fill(a6, 23);
        Arrays2.print("a6 = ", a6);
        Arrays.fill(a7, 29);
        Arrays2.print("a7 = ", a7);
        Arrays.fill(a8, 47);
        Arrays2.print("a8 = ", a8);
        Arrays.fill(a9, "Hello");
        Arrays2.print("a9 = ", a9);
        // Manipulating ranges:
        Arrays.fill(a9, 3, 5, "World");
        Arrays2.print("a9 = ", a9);
      }
    } ///:~
      

  2.   

    有这个静态方法,可能是设置有问题你到class所在目录下试试
      

  3.   

    class所在目录??什么意思,哪个class??
      

  4.   

    你编译出的 FillingArrays.class 所在目录
      

  5.   

    编译出错哪来的FillingArrays.class???
    而且既然我在编译我不在那目录下还能在哪??
      

  6.   

    把Arrays2的代码烤上来我运行一下
      

  7.   

    Arrays2  肯定没有这个方法
    public void fill (boolean[],boolean){}
      

  8.   

    不是Arrays2,是Arrays!Arrays2是BruceEckel自己写的,这个编译的时候没有任何问题,编译出错提示是java自身的Arrays有问题。
      

  9.   

    如果要试,就试下面这个简单的程序:
    //A.java
    import java.util.*;public class A {
    public static void main(String[] args) {
    int[] num = new int[5];
    Arrays.fill(num,20);

    }
    }
    看看Arrays.fill()能不能过。就是这个问题,我编译这个程序的时候也是出错找不到fill()。
      

  10.   

    Arrays 当然没有这个方法了,白痴也知道啊
    public void fill (boolean[],boolean){}你使劲添也白饶
      

  11.   

    呵呵,我觉得你这人真是搞笑,水平不高还嘴巴不干净。我告诉你我不算很菜的人,我英文和计算机底子都很好,java不过是我现在才学。Thinking in java你看过吗??如果你说Arrays里没这方法,那你就去跟BruceEckel报告他书里面的这个Bug吧!你看过java的API文档吗?写得情清楚楚java.util下有Arrays类,这下面又有Overloaded的各种fill()方法。
    如果你比我还菜,上面的这段话就算我教你入门!
      

  12.   

    怎么搞的刚才白写那么长了,发丢了简单说一下 JAVA的内制对象不是OBJECT的子类,如:boolean,int,double,float所以这个方法不能生效
    public void fill (Object[] o ){}
    而这个方法却没有,所以,,,,
    public void fill (boolean[],boolean){}
      

  13.   

    你如果换成API中的任何一个类都会成功的
    祝你玩的愉快
      

  14.   

    我实在没招了,不明白你说的意思,你还是仔细看看下面javaAPI文档的原文吧!static void fill(boolean[] a, boolean val) 
              Assigns the specified boolean value to each element of the specified array of booleans. 
    static void fill(boolean[] a, int fromIndex, int toIndex, boolean val) 
              Assigns the specified boolean value to each element of the specified range of the specified array of booleans. 
    static void fill(byte[] a, byte val) 
              Assigns the specified byte value to each element of the specified array of bytes. 
    static void fill(byte[] a, int fromIndex, int toIndex, byte val) 
              Assigns the specified byte value to each element of the specified range of the specified array of bytes. 
    static void fill(char[] a, char val) 
              Assigns the specified char value to each element of the specified array of chars. 
    static void fill(char[] a, int fromIndex, int toIndex, char val) 
              Assigns the specified char value to each element of the specified range of the specified array of chars. 
    static void fill(double[] a, double val) 
              Assigns the specified double value to each element of the specified array of doubles. 
    static void fill(double[] a, int fromIndex, int toIndex, double val) 
              Assigns the specified double value to each element of the specified range of the specified array of doubles. 
    static void fill(float[] a, float val) 
              Assigns the specified float value to each element of the specified array of floats. 
    static void fill(float[] a, int fromIndex, int toIndex, float val) 
              Assigns the specified float value to each element of the specified range of the specified array of floats. 
    static void fill(int[] a, int val) 
              Assigns the specified int value to each element of the specified array of ints. 
    static void fill(int[] a, int fromIndex, int toIndex, int val) 
              Assigns the specified int value to each element of the specified range of the specified array of ints. 
    static void fill(long[] a, int fromIndex, int toIndex, long val) 
              Assigns the specified long value to each element of the specified range of the specified array of longs. 
    static void fill(long[] a, long val) 
              Assigns the specified long value to each element of the specified array of longs. 
    static void fill(Object[] a, int fromIndex, int toIndex, Object val) 
              Assigns the specified Object reference to each element of the specified range of the specified array of Objects. 
    static void fill(Object[] a, Object val) 
              Assigns the specified Object reference to each element of the specified array of Objects. 
    static void fill(short[] a, int fromIndex, int toIndex, short val) 
              Assigns the specified short value to each element of the specified range of the specified array of shorts. 
    static void fill(short[] a, short val) 
              Assigns the specified short value to each element of the specified array of shorts. 
      

  15.   

    等一下,我刚才看了API,发现我是错的,,,,等等,我再看看
      

  16.   

    老大,这个我能运行import java.util.*;public class A {
    public static void main(String[] args) {
    int[] num = new int[5];
    Arrays.fill(num,20);

    }
    }
      

  17.   

    OS中classpath定义如下:
    .;d:\program files\jdk\bin;d:\program files\jdk\lib;d:\program files\jdk\jre;e:\j2se_doc\thinking in java\codeJcreator中classpath定义如下:
    D:\Program Files\jdk\jre\lib\rt.jar;
    D:\Program Files\jdk\lib\dt.jar;
    D:\Program Files\jdk\lib\tools.jar;
    D:\Program Files\jdk\jre\lib\ext\dnsns.jar;
    D:\Program Files\jdk\jre\lib\ext\ldapsec.jar;
    D:\Program Files\jdk\jre\lib\ext\localedata.jar;
    D:\Program Files\jdk\jre\lib\ext\sunjce_provider.jar;
    D:\Program Files\jdk\bin;
    D:\Program Files\jdk\lib但是我无论是用Jcreator还是本身的javac都不能编译成功,各位看一下是什么问题,谢谢!
      

  18.   

    更郁闷的是我运行这个:
    import java.util.*;public class A {
    public static void main(String[] args) {
    System.out.println(new Date());

    }
    }
    可以成功Date这个类也是在java.util下啊!跟Arrays在同一层目录。
      

  19.   

    JAVA这种问题很讨厌,解决起来比较复杂,干脆玩其他章节吧
      

  20.   

    另:
    classpath=
    .;d:\program files\jdk\bin;d:\program files\jdk\lib;d:\program files\jdk\jre;e:\j2se_doc\thinking in java\codeclasspath中放的应该是jar文件或是包含class文件的文件夹
    放d:\program files\jdk\bin没有意义还有这个:d:\program files\jdk\lib应该指定到具体的jar 文件
      

  21.   

    要把源代码里面的com目录到底你这个程序的目录下
      

  22.   

    CLASSPATH一般就不需要设置,除非你安装了JDBC驱动或别的要求设置CLASSPATH的。我也编译A.java成功了,我的CLASSPATH是:.;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
      

  23.   

    可我具体到jar也不行,还是Date那个能过, Arrays那个就过不了。哎这问题太怪了
      

  24.   

    哎!!整整一天,终于找到问题了!是出在classpath上!由于我把自己的包com\bruceeckel\util放在java的安装目录bin下,所以classpath中就设置了d:\program files\jdk\bin;正是这个引起了冲突,使得编译器找不到java自身的Arrays.fill()方法。我把这个路径删掉,然后将com\bruceeckel\util放到非java安装目录下,并对classpath做相应添加。呵呵!顺利通过!不过我说的这个只是表象的原因,至于为什么在添加了d:\program files\jdk\bin后编译器找不到java.util下的Arrays.fill()方法,却可以找到Date类,还请高手解释一下更深层的原因,谢谢各位了!
      

  25.   

    又继续看了一下
       问题的根源确实是同名类的存在!!!我把classpath设回到之前通过不了的情况,既加入d:\program files\jdk\bin后,按你的方法在Arrays.fill()前加上java.util.成功了!原来编译器先去找classpath里面的东西在bin目录下发现了同名类Arrays!呵呵,是我之前写的一个程序放到里面了,过了太久没注意这问题,然后我把那程序删了,再编译,就找正确了!非常感谢!!!