beginsWith 🌶️🌶️
Write a method that takes two String parameters, text and prefix, and returns true if text starts with prefix, and false otherwise. For example, beginsWith("hello", "he") should return true and beginsWith("hello", "lo") should return false. Build it with substring and equals. Be careful when prefix is longer than text: asking for that many characters would throw an exception, and the answer there is simply false.
How would you get the first part of text that's the same length as prefix? How do you compare two Strings for equal content?
What if prefix is LONGER than text? Then that substring call throws an exception. Check the lengths first (text.length() >= prefix.length()) and join the two tests with &&. Because && stops as soon as its left side is false, the substring is never evaluated when it would crash.