NEW
Font size
WorksheetsStings, Cloning and ArrayList
Total questions: 10
Worksheet time: 10mins
Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
concat()
append()
join()
concatenate()
What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
String a = "hello i love java"; System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));
}
}
6 4 6 9
5 4 5 9
7 8 8 9
1 14 8 15
What will be the output of the following Java code?
class output {
public static void main(String args[])
{
StringBuffer sb=new StringBuffer("Hello"); sb.replace(1,3,"Java");
System.out.println(sb);
} }
Hello java
Hellojava
HJavalo
Hjava
What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World"); s1.insert(6 , "Good ");
System.out.println(s1);
} }
HelloGoodWorld
HellGoodoWorld
HellGood oWorld
Hello Good World
Which of these method of Object class can clone an object?
Objectcopy()
copy()
Object clone()
None of the above
Which of these class can generate an array which can increase and decrease in size automatically?
ArrayList()
DynamicList()
LinkedList()
MallocList()
Which of these method can be used to increase the capacity of ArrayList object manually
Capacity()
increaseCapacity()
increasecapacity()
ensureCapacity()
Which of these methods can be used to obtain a static array from an ArrayList object?
Array()
covertArray()
toArray()
convertoArray()
What will be the output of the following Java program?
import java.util.*;
class Arraylist
{
public static void main(String args[])
{
ArrayList obj = new ArrayList();
obj.add("A");
obj.add("B");
obj.add("C");
obj.add(1, "D");
System.out.println(obj);
} }
[A, B, C, D]
[A, D, B, C]
[A, D, C]
[A, B, C]
What will be the output of the following Java program?
import java.util.*;
class Output
{
public static void main(String args[])
{
ArrayList obj = new ArrayList();
obj.add("A");
obj.ensureCapacity(3);
System.out.println(obj.size()); } }
1
2
3
4
