← all problems

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.