Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ibthaj Mansour   on Jun 21 In Java Category.

  
Question Answered By: Heidi Larson   on Jun 21

> There are a few things  I don't get:


> (1) what are these brackets  for,

They declare an Array.

> (2) do you ever put  anything inside  them,

Sometimes, but not where you have them :)

(3) do they only go after the word  "String"

No they can go after any Object (include an Object that you wrote yourself)

> (4) are you supposed to have a space  before
> the [] or not?

It doesn't really matter, but my advice is to not put a space after it.
At least untill you are a insane Code Ninja, then you can do what you
are want.

>
> Any help  on this would be great. The book  I'm using doesn't seem to
> explain these brackets--why they're there, what they're used for,
> etc. Are they just symbolic of something having to do
> with "arguments"? I'm totally clueless.

Someone will probably jump on my head for this description but I find
that people understand this idea of it more than other explanations.

Arrays are basically a list of stuff. The stuff you put into it are
Objects (like in your case String Objects).

String[] list;

This tells the Java compiler to get ready to remember a list of Strings
which will be called list.

list = new String[5];

This tells the Java compiler to make the list 5 elements long (from 0 – 4)

Then you could write stuff to the list like

list[0] = “ABC”;

Which would make the item in the very first element equal to the String
“ABC”.

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Confused about brackets (when used with String command) Or get search suggestion and latest updates.


Tagged: