Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (retired 2014) Getting Started with Android Introduction to Methods and Classes

is "toppings" in the method orderPizza a array or a string?

In the creation of the method public Pizza orderPizza(String toppings) { //code }

Is toppings an array or a string? How can i tell?

1 Answer

Pretty straightforward

Do not confuse with String and Array, they do not come under the same category. Array is a data structure, where as String is a data type. So you could have an Array which of the type String, Integer, Char, Float etc.

What you probably are looking to question is when and how to spot an array

When you pass the String data type (String is a class in Java and not a primitive type) itself -- the syntax would be as follows

public Pizza orderPizza(String toppings) 
{  //code 
    }

However when its an array it would, well have an array in the parameter list preceded by the dat type (denoted by two square brackets) like--

Note -- in java the default syntax is --- data_type variable_name;
The data type could not be a simple primitive or an array

public Pizza orderPizza(String [] toppings) 
{ //code 
   }

Hope this helps

Thanks Gunjeet. This helps.