String Flashcards

1
Q

It is a sequence of zero or more characters from the Unicode character set.

A

String

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

It is the sequence consisting of zero characters

A

Null string

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

What is it called when an object cannot be changed?

A

Immutable

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

Does a string change once created?

A

NO

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

If a string does not change once created, what happens instead?

A

Methods produce new strings from old ones

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

A representation for a string value within the program text

A

String Literal

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

In Java, it is a sequence of zero or more graphic characters from the Unicode character set or escape sequences, enclosed in double-quotes

A

String Literal

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

What is the syntax for string declaration?

A

String varname = value;

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

What does the following String function do?
charAt (int i)

A

Character at position i

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

What does the following String function do?
compareTo (String t)

A

Compare with t

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

What does the following String function do?
concat (String t)

A

Concatenation with t

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

What does the following String function do?
equals (String t)

A

Same characters as t

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

What does the following String function do?
equalsIgnoreCase

A

Same characters as t (ignoring case differences)

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

What does the following String function do?
indexOf (char c)

A

Position of the first occurence of c

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

What does the following String function do?
indexOf (String t)

A

Position of the first occurence of t

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

What does the following String function do?
length ()

A

Number of characters in String

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

What does the following String function do?
replace (char c, char d)

A

Replaces c with d

18
Q

What does the following String function do?
substring (int f int t)

A

Substring from position f up to but not including t

19
Q

What does the following String function do?
toLowerCase()

A

Equivalent string in all lowercase

20
Q

What does the following String function do?
toUpperCase()

A

Equivalent string in all uppercase

21
Q

What does the following String function do?
trim ()

A

Equivalent string without leading and trailing white space

22
Q

What would the output be?
String str = “programming”;
char ch = str.charAt(2)
System.out.println(“Character at charAt(2): “ + ch);
ch = str.charAt(5)
System.out.println(“Character at charAt(5): “ + ch);

A

Character at charAt(2): o
Character at charAt(5): a

23
Q

What would the output be?
System.out.println(“Character at charAt(2):” + ch);
String s1 = “Hello”;
String s2 = “Hello;”
String s3 = “HELLO”;
String s4 = “hello”;
System.out.println(“s1.compareTo(s2) “ + s1.compareTo(s2));
System.out.println(“s1.compareTo(s3) “ + s1.compareTo(s3));
System.out.println(“s1.compareTo(s4) “ + s1.compareTo(s4));

A

s1.compareTo(s2) 0
s1.compareTo(s3)
s1.compareTo(s4) -32

24
Q

What value is returned if the content of the strings are the same when using the compareTo function?

25
What value is returned if the first string comes before the second in alphabetical order when using the compareTo function?
A negative value
26
What value is returned if the first string comes after the second in alphabetical order when using the compareTo function?
A positive value
27
**What would the output be?** String s1 = "Hello"; String s2 = "Programming"; String s3 = "Enjoy"; String s4 = " s1.concat(s2); String s5 = "s4.concat(s3); System.out.println("s1.concat(s2)>> " + s4); System.out.println("s4.concat(s3)>> " + s5);
s1.concat(s2)>> HelloProgramming s4.concat(s3)>> HelloProgrammingEnjoy
28
**What would the output be?** String s1 = "Hello"; String s2 = "Hello;" String s3 = "HELLO"; String s4 = "hello"; System.out.println("s1.equals(s2) " + s1.equals(s2)); System.out.println("s1.equals(s3) " + s1.equals(s3)); System.out.println("s1.equals(s4) " + s1.equals(s4));
s1.equals(s2) true s1.equals(s3) false s1.equals(s4) false
29
**What would the output be?** String s1 = "Google classroom"; System.out.println("s1.indexOf('o') " + s1.indexOf('o')); System.out.println("s1.indexOf('c') " + s1.indexOf('c')); System.out.println("s1.indexOf('s') " + s1.indexOf('s')); System.out.println("s1.indexOf('G') " + s1.indexOf('G')); System.out.println("s1.indexOf('g') " + s1.indexOf('g')); System.out.println("s1.indexOf('x') " + s1.indexOf('x'));
s1.indexOf('o') 1 s1.indexOf('c') 7 s1.indexOf('s') 10 s1.indexOf('G') 0 s1.indexOf('g') 3 s1.indexOf('x') -1
30
**What would the output be?** String s1="The quick brown fox and the dog" System.out.println("s1.indexOf("the") "+s1.indexOf("the System.out.println("s1.indexOf("Thel")" + sindexOf("The System.out.println("s1.indexOf("fox\")" + s1.indexOf("fox")); System.out.println("s1.indexOf("Fox\") " + s1.indexOf("Fox")); System.out.println("s1.indexOf(\"cat")" + s1.indexOf("cat"));
s1.indexOf("the") 24 s1.indexOf("The") 0 s1.indexOf("fox") 16 s1.indexOf("Fox") -1 s1.indexOf("cat") -1
31
**What would the output be?** String str1="programming" System.out.println("str1.replace('m', 'g')>>"+str1.replace('m', 'g System.out.println("str1.replace(\"gram\", \"ham\") >> " str1.replace("gram", "ham"));
str1.replace('m', 'g')>> progragging str1.replace("gram", "ham") >> prohamming
32
**What would the output be?** String str1 = "programming"; System.out.println("str1.substring(1, 4): " + str1.substring(1, 4)); System.out.println("str1.substring(2, 7): " + str1.substring(2, 7)); System.out.println("str1.substring(3): " + str1.substring(3));
str1.substring(1, 4): rog str1.substring(2, 7): ogram str1.substring(3): gramming
33
It is when a method breaks a given string around matches of the given regular expression
Split
34
It returns an array of strings computed by splitting the given string
Split
35
Method in String class
Split
36
It returns an array of strings after splitting an input String based on the delimiting regular expression
String[] split(Spring regex)
37
This limits the number of strings returned after split-up
String[] split(String regex, int limit)
38
**What would the values of the array elements be?** String name = "Ana, Maria, Carla, Vina, Glen" String breakName[] = name.split(" ")
breakName[0] = Ana breakName[1] = Maria breakName[2] = Carla breakName [3] = Vina breakName[4] = Glen
39
**Split the following into the month, day, and year.** May 11, 2022
date = "May 11, 2002"; date1 = date.split(","); // date1[0] = May 11, // date1[1] = 2002 date2 = date1[0].split(" "); // date2[0] = May // date2[1] = 11 // date1[1] = 2002
40
String sentences = "Java Programming is fun and easy"; String splitSentence[] = sentence.split(" "); System.out.println("Sentence: " + sentence); System.out.println("After Split"); for (int x = 0; x
splitSentence[0] Java splitSentence[1] Programming splitSentence[2] is splitSentence[3] fun splitSentence[4] and splitSentence[5] easy