Font size
Worksheetsarrays and strings in java
Total questions: 25
Worksheet time: 19mins
Is String a primitive data type?
Yes
No
Both
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
What will be the output of below code?
String statement = "Outfit of the day";
System.out.println(statement.Substring(3,6));
it of
tfit
fit
FIT
Choose most appropriate purpose of trim() method in String?
to remove white spaces
to get a substring of the string
to cut String at desired index
to remove extra white spaces from start and end of String
(Multiple answer question)
Pick all NON-primitive datatypes from below :
String
int
primitive
Array
What is the correct relation between length and last-index of array?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
Select correct code to create an array of "double" datatype of length 5.
double arr = double[5];
double{} arr = new double{5};
double[5] arr = new double[];
double[] arr = new double[5];
Each item in an array has a numbered position.
True
False
Which of these operators is used to allocate memory to array variable in Java?
malloc
alloc
new
new malloc
Which of these is necessary to specify at time of array initialization?
Row
Column
Both Row and Column
None of the mentioned
Which of the following statements are incorrect?
String is a class
Strings in java are mutable
Every string is an object of class String
Java defines a peer class of String, called StringBuffer, which allows string to be altered
double[ ] data = new double[20];
data[20] = 15.25;
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
How many objects will be created?
String a = new String("Examveda");
String b = new String("Examveda");
String c = "Examveda";
String d = "Examveda";
4
3
2
none of these
Based on the code segment below:- identify the name of the array.
for(int j=0; j<balance.length; j++)
{
System.out.print("Enter amount: ");
.......
}
No answer.
temp[ ]
balance
balance [ i ]
Which of these is an incorrect statement?
String objects are immutable, they cannot be changed
String object can point to some other reference of String variable
StringBuffer class is used to store string in a buffer for later use
None of the mentioned
Which of the following is NOT a primitive data type?
double
float
boolean
String
What do we use the Scanner Library in java for?
Give permissions to the user
Correcting software errors
Allows user to read data
Allows the user to enter data
