0

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

3
  • 2
    They ARE different. One is array to multiple String objects, the other is a single String object. Commented Oct 24, 2012 at 17:44
  • what is the basic difference -> Why are you trying to compare Water, and Water container? Commented Oct 24, 2012 at 17:45
  • @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 .. Commented Oct 24, 2012 at 17:49

3 Answers 3

3
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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

Please declare var with lowerCamelCase.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.