Reputation: 2835
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
Upvotes: 0
Views: 4385
Reputation: 409
Please declare var with lowerCamelCase.
String [] wordsArray = {"first", "Second"..};
String words = "These are sample words";
Upvotes: 0
Reputation: 32391
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
.
Upvotes: 2
Reputation: 66637
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
Upvotes: 3