0
public class Test {
    public char[] reverse(String list) {           
        char[] ch=list.toCharArray() ;
           for (int i = 0, j = list.length() - 1; i < j; i++, j--) {
              char temp=ch[i];
              ch[i]=ch[j];
              ch[j]=temp;
           }
           return ch;
        }

   public static void main(String args[]) {
      Test test = new Test();
      String a="HELLo";
      char[] b=test.reverse(a);          
      System.out.println(a);
      System.out.println(b);
      System.out.println(a+b);
   }
}

Output: HELLo oLLEH HELLo[C@38462f90

In last s.o.p output is reference while for same vairable b in second s.o.p is string value. Please explain reason

Abubakar
  • 31
  • 1
  • 6
  • https://stackoverflow.com/questions/7655127/how-to-convert-a-char-array-back-to-a-string – E_net4 Jul 14 '17 at 12:57
  • 2
    Because `char[].toString()` returns `[C@` followed by the hex hashcode of the array. – Andy Turner Jul 14 '17 at 12:58
  • `a + b` is equivalent to `a + b.toString()` (which is a `String`), so `System.out.println(a + b)` invokes `PrintStream.println(String)`; on the other hand, `b` is a `char[]`, so `System.out.println(b)` invokes `PrintStream.println(char[])`, which handles the array "correctly". – Andy Turner Jul 14 '17 at 13:04
  • Thanks a lot @Andy – Abubakar Jul 15 '17 at 15:38

0 Answers0