Why does the toString method in java not seem to work for an array

后端 未结 9 1574
灰色年华
灰色年华 2020-11-22 12:25

I want to convert a character array to a string object using the toString() method in java. Here is a snippet of the test code I used:

import java.util.Array         


        
9条回答
  •  梦谈多话
    2020-11-22 12:56

    Arrays don't override toString. There's a static method: java.util.Arrays.toString that should solve your problem.

    import java.util.Arrays;
    class toString {
        public static void main(String[] args){
            char[] Array = {'a', 'b', 'c', 'd', 'e', 'f'};
            System.out.println(Arrays.toString(Array));
        }
    }
    

提交回复
热议问题