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 Java Objects (Retired) Delivering the MVP Arrays and Command Line Arguments

Why does the main class take an array?

For this Hangman game, what is the point of having an array? Can't it just be a normal string?

1 Answer

Youssef George
PLUS
Youssef George
Courses Plus Student 2,005 Points

Having an array in the main method is more flexible than a string for passing arguments because You will basically be able to pass more than one String and use it in your code, for example:

Imagine that you are making a java program that creates human objects and you will need to pass to the main method two strings, the first one is the age and the other is the name. Can you achieve that with one string? Yes you can but you will make the code a bit more complicated and that's why the main method needs an array of strings.

I hope that I was clear,

Happy Coding!