String manipulation Flashcards

1
Q

How do you split a sentence (ie., “My name is Bob”) by a space?

A

String s = “My name is Bob”;
String[] words = s.split(“ “);

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

If you have int[] numbers = { 1, 2, 3 }; what built in method can you used to sort it?

A

Arrays.sort(numbers);

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

If you have int[] array1 = { 1, 2, 3 }; and int[] array2 = { 1, 2, 3 };

What built in method can you use to check the 2 arrays are equal?

A

Arrays.equal(array1, array2);

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

How do you represent a int[] as a List<Integer>?</Integer>

A

int[] numbers = {1,2,3};
List<Integer> list = Arrays.asList(numbers);</Integer>

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

How can you use a built in Collections method to sort List<Integer> list = Arrays.asList(numbers);?</Integer>

A

Collections.sort(list);

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

How can you use a built in Collections method to reverse List<Integer> list = Arrays.asList(numbers);?</Integer>

A

Collections.reverse(list);

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

How do you check if a string contains vowels?

A
  1. Store the vowels as a String vowels = “aeiou”
  2. Loop through each char in s.toCharArray()
  3. and check if vowels.contains(String.valueOf(char))
  4. if it does increment the counter
  5. return the counter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly