Repository navigation
Expand file tree
/
Copy pathStringLecture.java
More file actions
118 lines (96 loc) · 3.65 KB
/
Copy pathStringLecture.java
File metadata and controls
118 lines (96 loc) · 3.65 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.Scanner;
public class StringLecture {
public static void main(String[] args) {
// int number1 = 10;
// int number2 = 20;
//
// //We are comparing the values when using primitives and ==.
// if(number1 == number2) {
// System.out.println("The numbers are equal.");
// }
// Scanner sc = new Scanner(System.in);
// System.out.print("Continue? [y/N] ");
// String userInput = sc.next();
//
// // Never do this!
// // boolean confirmation = userInput == "y";
//
// // Do this instead!
// if ("I am a string".equals("I am a string")) {
// System.out.println("Strings are equal");
// }
// System.out.println("Trim: " + " I am a string ".trim());
// //Never do this!
// if ("I am a string" == "I am a string ".trim()) {
// System.out.println("String references are equal.");
// } else {
// System.out.println("String references are not equal. ");
// }
//
// //Always do this when dealing with Strings.
// //Test for value
// if ("I am a string".equals(" I am a string ".trim())) {
// System.out.println("String values are equal.");
// } else {
// System.out.println("String values are not equal. ");
// }
// .equalsIgnoreCase(String anotherString)
// String greeting = "howdy";
// System.out.println(greeting.equalsIgnoreCase("HoWDy"));
// .startsWith(String prefix)
// String title = "Dr. Doctor";
// boolean isADoctor = title.toLowerCase().startsWith("dr");
// System.out.println("isADoctor = " + isADoctor);
// .endsWith(String suffix)
// String codeupDallas = "701 Commerce St #100A, Dallas, TX. 75202";
// String downtownDallasZip = "75202";
// boolean sameZipAsCodeup = codeupDallas.endsWith(downtownDallasZip);
//
// System.out.println(sameZipAsCodeup);
// .charAt(int index)
// boolean firstLetterCapitalized = false;
// String word = "Test";
//
// char firstLetter = word.charAt(0);
//
// if (firstLetter == Character.toUpperCase(firstLetter)) {
// firstLetterCapitalized = true;
// }
//
// System.out.println(firstLetterCapitalized);
// .indexOf(String subString)
// String cat = "cat";
// System.out.println(cat.indexOf("at"));
// .lastIndexOf(String subString)
// String good = "Good";
// System.out.println(good.lastIndexOf("o"));
// .length()
// String longestWord = "pneumonoultramicroscopicsilicovolcanoconiosis";
// System.out.println(longestWord.length());
// .replace(char oldChar, char newChar)
// String search = "tiny cats looking cute";
// String parsedSearch = search.replace("cats", "dogs");
// System.out.println(parsedSearch);
// .substring(int beginIndex[, int endIndex])
// String name = "Justin Bob Reich";
// String firstName = name.substring(0, name.indexOf(" "));
//
// String lastName = name.substring(name.lastIndexOf(" ") + 1);
// System.out.println(firstName);
// System.out.println(lastName);
// .toLowerCase()
// .toUpperCase()
//
// String hello = "hELlo";
// System.out.println(hello.toUpperCase());
// System.out.println(hello.toLowerCase());
// System.out.println(hello);
// .trim()
//
// String input = " bob smith\n ";
// String trimmedInput = input.trim();
// System.out.println("|" + trimmedInput + "|");
//
// System.out.println("|" + input + "|");
}
}