Question: 2.7.3. Common Mistakes with Strings The following code shows some common mistakes with strings. This code contains some common mistakes with strings. Fix the code

 2.7.3. Common Mistakes with Strings The following code shows some common

2.7.3. Common Mistakes with Strings The following code shows some common mistakes with strings. This code contains some common mistakes with strings. Fix the code to use the string methods correctly Run Load History Show CodeLens 6 7 // Print out the first letter? System.out.println("The first letter in 8 + strl + ":" + stri.substrin 9 10 // Print out the last character? System.out.println("The last char. in 11 + strl + + str1.substring 12 13 14 // Print stri in lower case? Will str1 change? stri.toLowerCase(); System.out.println("In lowercase: + stri); 15 16 17 } 18 } 19 ActiveCode (code2_7_3) Here is a list of common mistakes made with Strings. Thinking that substrings include the character at the last index when they don't. Thinking that strings can change when they can't. They are immutable. Trying to access part of a string that is not between index 0 and length - 1. This will throw an IndexOutOfBoundsException. Trying to call a method like indexof on a string reference that is null. You will get a null pointer exception Using == to test if two strings are equal. This is actually a test to see if they refer to the same object. Usually you only want to know if they have the same characters in the same order. In that case you should use equals or compareto instead. Treating upper and lower case characters the same in Java. If s1 = "Hi" and s2 = "hi" then si.equals(52) is false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!