i am beginner in java and want to ask a basic question

While reading Strings and Arrays i came to see sometimes we use String Type Arras like this

String   Words[]={"first ", "Second"..};
String  words="These are sample words"; 

and some more ways to declare it . I want to ask that what is the basic difference between the two mentioned Strings .. i mean why we need to declare String Type Array instead of String obj= ..; etc . Can someone please explain

share|improve this question
2  
They ARE different. One is array to multiple String objects, the other is a single String object. – nhahtdh 15 hours ago
what is the basic difference -> Why are you trying to compare Water, and Water container? – Rohit Jain 15 hours ago
@RohitJain i have been using both of them , basically i want to ask that when we are doing a project do we use it as per scenario or both can do same thing .. – Sikander 15 hours ago
feedback

3 Answers

Strings  words="These are sample words"; 

doesn't compile. There is no Strings type available in java.

You might be referring

String  words="These are sample words"; 

The difference between above and array is, above is single String. String[] will be used to store multiple *String*s

share|improve this answer
Oh, well, a simple typo... – rolve 15 hours ago
feedback

The first line declares and initializes an array of String objects, while the second one, once you fix the compilation error (Strings should be String) declares and initializes a single String.

share|improve this answer
feedback

Please declare var with lowerCamelCase.

String [] wordsArray = {"first", "Second"..};
String  words = "These are sample words";
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.