Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Phoenix S.
Phoenix S.
2,456 Points

Why does using sweetFlavors/savoryFlavors generate this?

When I changed the code to

for (String sweet : sweetFlavors) {
      for (String savory : savoryFlavors) {
        console.printf("%s and %s %n", sweetFlavors, savoryFlavors);
      }
    }

the out put was :

[Ljava.lang.String;@15db9742 and [Ljava.lang.String;@6d06d69c

can some break down for me why this happens??

2 Answers

Oscar Acevedo
Oscar Acevedo
8,240 Points

Hey there, try changing this line

console.printf("%s and %s %n", sweetFlavors, savoryFlavors);

to this

console.printf("%s and %s %n", sweet, savory);

You are printing the array object which is why you're getting [Ljava.lang.String;@15db9742 and [Ljava.lang.String;@6d06d69c.

Phoenix S.
Phoenix S.
2,456 Points

I had it correct. I just want an explanation as to why it returns the array object.

Hi Phoenix. Could you please share the link of the challenge or video it refers to? Thanks :)