Q:

Java toString method in char[]

I thought the toString method will make a char array to a String, but I was wrong.
    char[] k=new char[2];
    k[0]='k';
    k[1]='k';
    System.out.println(k.toString());

This code will output: [C@112f614.
What exactly happened in this code k.toString()?
Should I never call toString method in a char array?
Thanks!
Happy New Year!

A:

You want to use Arrays.toString(char[]{'a','b'});

You can use
char data[] = {'a', 'b', 'c'};
     String str = new String(data);

See the javadoc

public String(char[] value) 
  Allocates a new String so that it
  represents the sequence of characters currently contained in the
  character array argument. The contents of the character array are
  copied; subsequent modification of the character array does not affect
  the newly created string. Parameters: value - The initial value of the
  string

http://docs.oracle.com/javase/6/docs/api/java/lang/String.html
Calling toString on an array will call the toString method from Object. Which will return you the hashCode

public String toString() Returns a string representation of the
  object. In general, the toString method returns a string that
  "textually represents" this object. The result should be a concise but
  informative representation that is easy for a person to read. It is
  recommended that all subclasses override this method. The toString
  method for class Object returns a string consisting of the name of the
  class of which the object is an instance, the at-sign character `@',
  and the unsigned hexadecimal representation of the hash code of the
  object. In other words, this method returns a string equal to the
  value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
  Returns: a string representation of the object.

