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 trialRamya reddy
Courses Plus Student 1,746 Pointsis "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
Gunjeet Hattar
14,483 PointsPretty 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
Ramya reddy
Courses Plus Student 1,746 PointsRamya reddy
Courses Plus Student 1,746 PointsThanks Gunjeet. This helps.