-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBasicStringUtils.java
More file actions
50 lines (45 loc) · 1.77 KB
/
BasicStringUtils.java
File metadata and controls
50 lines (45 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.dtcc.exams.fundamentals;
public class BasicStringUtils {
/**
* @param string1 - Base string to be added to
* @param string2 - String to add to `string1`
* @return concatenation of `string1` and `string2`
*/
public static String concatentate(String string1, String string2) {return string1+string2;}
/**
* @param string1 - String to be reversed
* @return an identical string with characters in reverse order
*/
public static String reverse(String string1) {
String temp = "";
for(int i = string1.length()-1; i >= 0; i--){
temp += string1.charAt(i) + "";
}
return temp;
}
/**
* @param string1 - first string to be reversed
* @param string2 - second string to be reversed
* @return concatenation of the reverse of `string1` and reverse of `string2`
*/
public static String reverseThenConcatenate(String string1, String string2) {
return reverse(string1) + reverse(string2);
}
/**
* @param string - the string to be manipulated
* @param charactersToRemove - Characters that should be removed from `string`
* @return `string` with `charactersToRemove` removed
*/
public static String removeCharacters(String string, String charactersToRemove) {
String temp = string.replaceAll("[" + charactersToRemove +"]", "");
return temp;
}
/**
* @param string - the string to be manipulated
* @param charactersToRemove - characters to be removed from the string
* @return reverse of `string` with `charactersToRemove` removed
*/
public static String removeCharactersThenReverse(String string, String charactersToRemove) {
return reverse(removeCharacters(string, charactersToRemove));
}
}