Chapter 9 Array and Sring in Java
Chapter 9 Array and Sring in Java
Section - A
‣ Choose the correct option from those given below each question. (Each question carries 1 Marks) (100)
01. Strings are enclosed in........brackets.
d
A. double quotes B. sings quotes C. curly D. square
an
Ans
An
02. What is the use of length property in 2- array .
A. Returns the number of rows B. Returns the number of columns.
ol
C. counts the length of a string D. None of these
ho
Ans
Sc
03. Which constructor will create a string object using variable's initial value?
A. String (char ary[ ]) B. String0 C. String (String String) D. String (String literal
h
ig
Ans
H
Ans
le
05. ....... method can create Date object using current time of system.
ow
Ans
06. If 'str' is the object of String class and its content is "Thank GOD", then what is the value of str.length()?
A. 9 B. 10 C. 8 D. 11
Ans
07. java.util.Arrays.fill(list 2, 6, 5), Which elements will be filled with 5 ?
A. list[2] to list [5] B. list[2] to list [61] C. list[2] to list [6] D. Error message occurs
Ans
08. Which method is not available for string class in Java ?
A. To cut some part of the string
B. To get the particular character for the given index position
C. To reverse the string
D. To divide the string to the substrings
Ans
09. What does mark[0] indicate?
A. Value of marks variable is zero. B. Last element of array
C. First element of array D. Such array variable is not possible
Ans
Page 1
10. …………method converts all the characters of a string to the small letter characters.
A. LowerCase() B. String toLowerCase() C. String toLowercase[] D. lowercase()
Ans
11. ...... package has the feature of using Calendar class.
A. java.lib.util B. java.utilities C. java.util D. javlibprop
Ans
12. What is Index position in array ?
A. Each element of an array B. Sequence of an array
C. Value of each array element D. None of these
Ans
13. data type should be used instead of char to include a character using less space.
A. String B. Character C. bytes D. number
Ans
d
14. How many values can be stored using int marks [ ] [ ] = new int[5] [3] ?
an
A. 5 B. 3 C. 15 D. 20
An
Ans
15. What is a string?
ol
A. One type of a character B. Series of characters
ho
C. Special type of character D. None of these
Sc
Ans
16. Array size can be mentioned in.
h
A. { } B. <> C. || D. ()
ig
H
Ans
17. If the calendar is the object of Calendar class then…………… date is set by giving calendar.set(Calendar.DATE,
e
dg
20).
A. 10 B. 20 C. 30 D. 1
le
Ans
ow
Page 2
23. ……………method is used to find the particular element in an array.
A. binaryFind() method B. binarySearch() method C. display() method D. Search() method
Ans
24. ......... subclass of Calendar class is used in our syllabus.
A. GeoCalendar B. GregorianCalendar
C. StandardCalendar D. MainCalendar
Ans
25. Array are passed to a function argument by…………… .
A. value B. reference
C. both value and reference D. none of these
Ans
26. Size of......... is indicated by first bracket in int marks [ ] [ ] = new int [5] [3] .
A. rows B. column C. cell D. none of these
Ans
d
an
27. Array with ......... dimension is known as 1-D array.
A. double B. triple C. (A) and (B) both D. single
An
Ans
ol
28. syntax is not true for declaring marks array.
ho
A. int marks [] = (90, 70, 77); B. int[] marks = {90, 70, 77};
C. int [3] marks = (90, 70, 77); D. All of these
Ans
Sc
h
29. String () without arguments create a……….object with no character.
ig
A. string B. character C. buffer D. code
H
Ans
e
dg
Ans
31. What is an array ?
Kn
Page 3
A. byte 11 B. getBytes [] C. byte[] getBytes [ ] D. getBytes()
Ans
36. Which arrays elements are changed by giving java.util.Arrays.fill(list 7) ?
A. All elements of array are filled with 7.
B. 7th element of array is filled with 7.
C. All elements after 7th are filled with 7
D. Error message occurs
Ans
37. What type of value is returned when we use get method of Calendar class with constantDAY OF WEEK as an
argument?
A. int B. char C. string D. boolean
Ans
38. ......... bracket is used to declare 1-D array.
A. () B. { } C. [] D. < >
d
Ans
an
39. To give the initial values to each element in 2-D array, the values separated by comma are given in .........
An
brackets.
A. [] B. ( ) C. {} D. < >
ol
Ans
ho
40. Method void... ......... copies characters of invoking string fromIndx to toIndx-1 to target array from targetIndx
Sc
onwards.
A. toUpperCase()
h
B. toLowerCase()
ig
C. concat(String str)
H
Ans
dg
A. 3 B. 4 C. 2 D. Only one
ow
Ans
Kn
Page 4
A. size of second dimension B. number of dimensions
C. size of first dimension D. number of elements
Ans
48. What can not be given simultaneously while declaring the array in java ?
A. Array name and size of dimension
B. Size of dimension and initial values of elements
C. Array name and number of elements
D. Any of above
Ans
49. How many bytes are used to store integer value using int data type?
A. 2 B. 4 C. 8 D. Only one
Ans
50. If two string objects are created using same string literal then what is done for the second object by the
memory?
d
A. Does not allocate the space B. Allocates double space
an
C. Allocates space D. Nothing is done
An
Ans
51. Which elements are sorted by giving 35) java.util.Arrays.sort (list 1, 5) ?
ol
A. list [1] to list [5] B. list [1] to list [51] C. list [0] to list [51] D. None of these
ho
Ans
Sc
52. If String str="Divyakant Sir" then which of the following constructor can create same string object as str?
A. String B. String String strObj C. String String literal) D. String char ary ID
h
ig
Ans
H
Ans
le
Ans
55. ……….. type of data can be stored in 2-D array.
A. Tabular B. Matrix C. (A) and (B) both D. (A) or (B)
Ans
56. The array size is same as the number of values specified in………….
A. braces B. index C. default value D. initialization
Ans
57. ..... is the wrong way to declare to marks array.
A. int marks [ ] = int[5]; B. int marks [] = new int [5];
C. int[] marks new int [5]; D. All of these
Ans
58. Which of the following refer to the starting index value in arrays?
A. 0 B. 1 C. null D. All of these
Ans
59. ....... class method is given when array is used in java.
A. Using private static B. Using public static C. Using protect static D. This is not possible
Ans
Page 5
60. ......... method is used to create an array.
A. Using new operator and defining its size
B. To directly initialize the value to array elements.
C. (A) or (B)
D. (A) and (B) both
Ans
61. Position of index start with.
A. 0 B. -1 C. 1 D. 2
Ans
62. Maximum...... dimension can be given to make 2-D array.
A. [8] [8] B. [16] [16] C. [255] [255] D. There is no limit
Ans
63. ………..is used to represent two dimensional (2-D) data structures like table or rows and columns.
A. Vector B. Path C. Matrix D. Route
d
an
Ans
64. When an array sales (512) is declared without specifying initial values, what is the initial value of sales[0] [0]?
An
A. 0 B. DEFAULT VALUE C. compilation error D. 60
ol
Ans
ho
65. Using………… method of Calendar class we can set the field constants.
A. Set B. get C. set D. Get
Ans
Sc
h
66. If an array is declared as a[10], then its elements will be stored as
ig
A. a[1] to a[10] B. a[1] to a[9] C. a[0] to a[9] D. a[0] to a[10]
H
Ans
e
dg
Ans
68. How many steps are there to create an array ?
Kn
A. 2 B. 3 C. 4 D. 5
Ans
69. Basic variable can store only one value. Such variable is known as
A. constant variable B. scalar variable C. modular variable D. (A) or (B)
Ans
70. ………….is false about an array.
A. Array is the word used to manage the list of things in java.
B. Array creation is the process of three steps
C. Array object can be created using two ways
D. When same task to be done different elements then array is used.
Ans
71. String str = "Saraswati Vidhyalaya"; System.out.println(str.length()); What will be the output of this program?
A. 18 B. 19 C. 20 D. 21
Ans
72. How is the data stored in 2-D array ?
A. In the form of row and column B. In a tabular form
C. (A) and (B) both D. (A) or (B)
Page 6
Ans
73. What is the meaning of length for array variable?
A. Method B. Properties C. Attribute D. (B) or (C)
Ans
74. int marks[] = new int [5], then which is true. about this array ?
A. Marks is the name of an array. B. Stores the five integer values.
C. Indicates the indexes also. D. All of these
Ans
75. …………………..method is provided by string class.
A. To convert the characters of a string to uppercase or lowercase.
B. String or its part to be copied
C. To convert the string to bytes array.
D. All of these
Ans
d
an
76. ......... syntax is true to declare 1-D array.
A. <data type> <array name> [ ]; B. <data type> [] <array name>
An
C. (A) and (B) both. D. <data type> [] {array name};
ol
Ans
ho
77. What will be the value of marks[3] in int marks [] = {90, 60, 70, 65, 80} ?
A. 70 B. 65 C. 3 D. 80
Ans
Sc
h
78. In 2-D array, row is taken as ..... array element.
ig
A. 1-D B. infinite C. 2-D D. multi
H
Ans
e
dg
Ans
ow
80. Which property is used to count the number of elements in 1-D array ?
Kn
Page 7
Ans
85. int marks [][] = new int [5] [3], the logical view of array elements is a table of……….. .
A. 3 rows and 5 columns B. 15 columns C. 5 rows and 3 columns D. 15 rows
Ans
86. ……………is the facility of string class method.
A. To compare two strings B. To get the length of strings
C. To concatenate two strings D. All of these
Ans
87. If the method calling string object is same as parameter str then......... value is returned.
A. - 1 B. 0 C. 1 D. < 0
Ans
88. Java library also provides ......... class in java.util package
A. data B. string C. time D. none of these
d
Ans
an
89. Pair of........... brackets are used to declare 2-D array in java.
An
A. () () B. [] [] C. {} {} D. <><>
Ans
ol
90. If the string and parameter str(object) are same then.......... value is returned.
ho
A. True B. False C. Wrong D. Error
Sc
Ans
91. Elements in 1-D array are separated using…………
h
ig
A. [ ] B. {} C. () D. <>
H
Ans
e
Ans
93. If we initialize the values of variables directly then operator is not needed.
A. new B. create C. array name D. all of these
Ans
94. The array variable marks[5] has an index value from.........
A. 1 to 5 B. 0 to 4 C. 0 to 5 D. 1 to 4
Ans
95. ........ method returns the number of characters lying in the string object.
A. int leno B. int length() C. int count() D. int encount()
Ans
96. If two strings are same the using operator different locations are assigned in the memory.
A. create B. new C. CREATE D. Set
Ans
97. What is the size of second dimension in an array sales [5][12] ?
A. 5 B. 12 C. 60 D. 10
Ans
Page 8
98. Method long...... returns number of milliseconds since January 1, 1970 GMT.
A. Date (long elapsed Time) B. Date()
C. toString() D. getTime()
Ans
99. What do we give in the [] after the array name?
A. Index B. Subscript C. (A) or (B) D. None of these
Ans
100. Which statement is false related to strings in Java?
A. Group of characters means a string
B. There are three types of strings in Java.
C. Strings are controlled using the classes like 'String' and 'StringBuffer'
D. Strings are enclosed in double quotes
Ans
d
an
An
ol
ho
Sc
h
ig
H
e
dg
le
ow
Kn
Page 9
ANSWERS
Section - A
‣ Choose the correct option from those given below each question. (Each question carries 1 Marks) (100)
01. double quotes
02. Returns the number of rows
03. String (char ary[ ])
04. Method
05. Date()
06. 9
d
an
07. list[2] to list [61]
08. To reverse the string
An
09. First element of array
ol
10. String toLowerCase()
ho
11. java.utilities
12. Each element of an array
Sc
13. bytes h
14. 15
ig
15. Series of characters
H
16. ||
e
17. 20
dg
19. 1
ow
Page 10
39. {}
40. getChars (intfromIndx, inttolndx, char target[], inttargetIndx)
41. 2
42. 2
43. Linear search
44. ()
45. 60
46. ASCII
47. size of first dimension
48. Array name and size of dimension
49. 4
50. Allocates space
51. list [1] to list [51]
52. String String strObj
d
53. display()
an
54. java.util.Arrays
An
55. (A) or (B)
56. braces
ol
57. int marks [ ] = int[5];
ho
58. 0
Sc
59. Using private static
60. (A) or (B)
h
ig
61. 0
H
63. Matrix
dg
65. set
ow
68. 2
69. (A) or (B)
70. Array creation is the process of three steps
71. 19
72. In the form of row and column
73. (B) or (C)
74. All of these
75. All of these
76. (A) and (B) both.
77. 65
78. 1-D
79. java.char
80. length
81. long
82. marks[0], marks[1], marks[2], marks[3], marks[4].
83. 0
84. five
Page 11
85. 5 rows and 3 columns
86. All of these
87. 0
88. none of these
89. [] []
90. True
91. {}
92. To get number of words
93. new
94. 0 to 4
95. int length()
96. new
97. 12
98. getTime()
d
99. (A) or (B)
an
100. There are three types of strings in Java.
An
ol
ho
Sc
h
ig
H
e
dg
le
ow
Kn
Page 12