wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Stings, Cloning and ArrayList

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

a)

concat()

b)

append()

c)

join()

d)

concatenate()

2.

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'));

}

}

a)

6 4 6 9

b)

5 4 5 9

c)

7 8 8 9

d)

1 14 8 15

3.

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);

} }

a)

Hello java

b)

Hellojava

c)

HJavalo

d)

Hjava

4.

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);

} }

a)

HelloGoodWorld

b)

HellGoodoWorld

c)

HellGood oWorld

d)

Hello Good World

5.

Which of these method of Object class can clone an object?

a)

Objectcopy()

b)

copy()

c)

Object clone()

d)

None of the above

6.

Which of these class can generate an array which can increase and decrease in size automatically?

a)

ArrayList()

b)

DynamicList()

c)

LinkedList()

d)

MallocList()

7.

Which of these method can be used to increase the capacity of ArrayList object manually

a)

Capacity()

b)

increaseCapacity()

c)

increasecapacity()

d)

ensureCapacity()

8.

Which of these methods can be used to obtain a static array from an ArrayList object?

a)

Array()

b)

covertArray()

c)

toArray()

d)

convertoArray()

9.

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)

[A, B, C, D]

b)

[A, D, B, C]

c)

[A, D, C]

d)

[A, B, C]

10.

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()); } }

a)

1

b)

2

c)

3

d)

4