String Handling Flashcards

1
Q

String is available under which package

A

java.lang

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Assigning string

A
  1. Direct assignment
  2. Assignment using new keyword
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Char charAt(int index) does what

A

Returns character from given index number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does int index of(char ch) do

A

Returns first occurence of character from given index number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does string substring (int start_index) do

A

Extracts all characters after the given index number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax of replace function

A

String.replace(character to replace, character to appear)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does String 1 concat(String 2) do

A

Joins two strings together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does String trim() do

A

Remove leading and trailing blanks from a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does String Boolean ends with(String s) and startsWith do?

A

Check if a suffix and prefix is present respectively

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does primitive type valueOf(String s) do?

A

Used to covert a string to primitive data type of respective wrapper class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is StringBuffer

A

Another type of class with some added functionality to handle strings. You can declare object of StringBuffer type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

characteristics of StringBuffer

A
  1. refers to specific length in memory to contain characters
  2. length can be changed using setLength() function.
  3. if the String has a bigger length than of StringBuffer object, then extra characters are truncated
  4. if string has a shorter length than StringBuffer object, extra characters such as ‘\u0000’ are in empty spaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is append() used for

A

to add a string at the end of another string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is setCharAt(index, character) used for

A

replace a character with another character available at specific index of string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is insert(int index, String) used for

A

insert a String at a specified index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is delete(int index1, int index2) used for

A

to delete characters from one index to another index in the given string

17
Q

what is setLength(int value) used for?

A

when length of StringBuffer variable is not sufficient to store a string, length of variable can be increased as per our requirement

18
Q

what is reverse() used for

A

reverse characters of a given string