Printing array shows wrong output

前端 未结 3 794
感动是毒
感动是毒 2021-01-27 22:36

What is wrong with this code I\'m getting wrong output. I don\'t know what\'s wrong, I hope you could help me:

public class Main{
  public static void main(Strin         


        
3条回答
  •  星月不相逢
    2021-01-27 23:02

    The toString() for arrays is broken. You need

    import java.util.Arrays;
    
    System.out.println("numbers are" + Arrays.toString(data));
    

    The same applies for Arrays.equals(), Arrays.hashCode(). The Array, Arrays, ArrayUtils classes add functionality you might like arrays to have.

    http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html

    http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html

    http://docs.oracle.com/javase/7/docs/api/java/sql/Array.html

    http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/ArrayUtils.html

    However, you may find that you really want ArrayList instead.

提交回复
热议问题