-2

I try to add a string "hello" into an array list, and convert the array list back into a string array, but I get weird output like this: [Ljava.lang.String;@1f26ecd2. What's the problem with that?

String s="hello";
   ArrayList<String> base = new ArrayList<String>();
   int a=0;
   if(a==0)
   {
       base.add(s);
   }
        String[] get=base.toArray(new String[base.size()]);
        System.out.print(get);
nojava
  • 1

3 Answers3

0

You need to use a loop to cycle get array to print its element. If you print directly the array of string, you get the objec codename

gderaco
  • 2,322
  • 1
  • 16
  • 18
0

If you want to print array values, use Arrays.toString()

System.out.print(Arrays.toString(get));
Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
0

It's not an error.. change the last line of that code to

System.out.print(get[0]);
Nick Dickinson-Wilde
  • 1,015
  • 2
  • 15
  • 21