Strings are such an important type of data that we have to deal with almost in each program. So what do we usually do with strings?
B. Common string operations
String variables and literals
4+7+"Hi" vs "Hi"+4+7
String length and index: length()
a character of a string: charAt();
Search for a substring: indexOf(), lastIndexOf(), contains()
compare strings: compareTo()
Starting: //convert variables to final values
str = "harry" n = 5 mystery = str.substring(0,1) + str.substring(4,5) Output: //hy Explanation: //notice that mystery is a string, which means it will concatenate. str.substring(0,1) is starting from h, and does not include a. So the first one is h. The next one is also pretty straightforward. Beginning index and ending index.