Search Header Logo

3CSE2 Lab Day-7

Authored by Sharfuddin Mohammed

Computers

University

Used 1+ times

3CSE2 Lab Day-7
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the primary purpose of StringBuffer in Java?

The primary purpose of StringBuffer in Java is to provide a mutable sequence of characters for efficient string manipulation.

To create immutable strings in Java.

To store a fixed number of characters.

To provide a method for string comparison.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How does StringBuilder improve performance over StringBuffer?

StringBuilder automatically manages memory allocation, unlike StringBuffer.

StringBuilder is synchronized, making it safer for multi-threaded environments.

StringBuilder improves performance over StringBuffer by being non-synchronized, reducing overhead in single-threaded environments.

StringBuilder uses more memory than StringBuffer, leading to slower performance.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which method in StringTokenizer is used to check if there are more tokens?

getTokenCount

hasMoreTokens

nextToken

isTokenAvailable

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the difference between StringBuffer and StringBuilder in terms of thread safety?

Both StringBuffer and StringBuilder are thread-safe.

StringBuffer is faster than StringBuilder.

StringBuffer is thread-safe; StringBuilder is not.

StringBuilder is thread-safe; StringBuffer is not.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you convert a StringTokenizer to an array of strings?

Convert the StringTokenizer to a List using Collections.list().

Use a loop to collect tokens into a List, then convert it to an array with list.toArray(new String[0]).

Use String.split() method directly on the string.

Call the toArray() method on the StringTokenizer instance.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What method would you use to append a string to a StringBuilder?

stringBuilder.insert("yourString");

stringBuilder.addString("yourString");

stringBuilder.concat("yourString");

stringBuilder.append("yourString");

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Explain how String manipulation can affect performance in Java applications.

String operations are faster than primitive data types.

String manipulation has no impact on performance.

String manipulation can lead to performance issues due to object creation overhead and memory usage.

Using StringBuilder always improves performance.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?