Java Programs  «Prev 

Building Character with Strings

You work with text in a Java program by using strings, which are comprised of a series of text characters. Following are some examples of strings:
"Howdy", "ABC", "123", "$99.99", and "Hello, world."

Since strings consist of a series of characters, they have a length associated with them. The length of a string is simply how many characters there are in the string. You can also access and manipulate individual characters within a string.

Creating and Using Arrays

Which of the following statements are valid ?
Select 2 options
  1. String[ ] sa = new String[3]{ "a", "b", "c"};
  2. String sa[ ] = { "a ", " b", "c"};
  3. String sa = new String[ ]{"a", "b", "c"};
  4. String sa[ ] = new String[ ]{"a", "b", "c"};
  5. String sa[ ] = new String[ ] {"a" "b" "c"}
Answer: b,d
a. You cannot specify the length of the array ( i.e. 3, here) if you are using the initializer block while declaring the array.
c. Here sa is not declared as array of strings but just as a String.
e. There are no commas separating the strings.