-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGL_StringsTest.java
More file actions
45 lines (42 loc) · 1.46 KB
/
GL_StringsTest.java
File metadata and controls
45 lines (42 loc) · 1.46 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
public class Main {
public static void main(String[] args) {
String myStr = "My best education project in GlobalLogic";
String myStr1 = "Cartoon";
String myStr2 = "Tomcat";
System.out.println(myStr.indexOf('a'));
System.out.println(myStr.lastIndexOf('b'));
System.out.println(myStr.substring(3, 7));
System.out.println(reverseString(myStr));
System.out.println(findUnique(myStr1, myStr2));
System.out.println(uniqueChars("Using methods of class String"));
}
public static String reverseString(String string){
int strLen = string.length();
String resStr = "";
for (int i = strLen-1; i >= 0 ; i--) {
resStr += string.charAt(i);
}
return resStr;
}
public static String findUnique(String str1, String str2){
String resStr = "";
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
for (int i = 0; i < str1.length()-1; i++) {
if (str2.indexOf(str1.charAt(i)) == -1) {
resStr += str1.charAt(i);
}
}
return resStr;
}
public static char[] uniqueChars(String str){
str = str.toLowerCase();
String resStr = "";
for (int i = 0; i < str.length()-1; i++) {
if (resStr.indexOf(str.charAt(i)) == -1) {
resStr += str.charAt(i);
}
}
return resStr.replaceAll("\\s", "").toCharArray();
}
}