Today in class, we started off by talking about the difference between strings and characters. Characters just store one character at a time but strings are made up of multiple characters. Each character has an integer it corresponds to. You can see which character corresponds to what integer here: https://www.asciitable.com/
Concatenation means combining different things into one string. The operation we use for this is a plus sign (+).
For example,
String a = "Hello";
char b = 'a';
int c = 1;
System.out.println(a + b + c);
would print out "Helloa1".
We also learned about other string operations.
String length and index: length()
A character of a string: charAt():
Substrings: substring()
Search for a substring: indexOf(), lastIndexOf(), contains()
Comparing strings: compareTo()
For example,
String a = "Hello World";
System.out.println(a.length()); //This will print out "11"
System.out.println(a.charAt(2)); //This will print out "l"
System.out.println(a.substring(1, 4); //This will print out "ell"
System.out.println(a.indexOf("Hello")); //This will print out "0"
System.out.println(a.lastIndexOf("l")); //This will print out "9"
System.out.println(a.contains("World")): //This will print out "true"
Here are some methods to compare strings:
boolean equals()
boolean equalsIgnoreCase()
int compareTo()
int compareToIgnoreCase()
trim()
toUpperCase()
toLowerCase()
Here's the homework for this week: https://docs.google.com/forms/d/e/1FAIpQLSf6_GW5MSvlQv6rjZsBrOsT2P7xHRcDE_V6Z69J7jWWqmEYiw/viewform?usp=sf_link
Homework solution: https://replit.com/@liizz/113-Homework-Solution#Main.java