1class Solution {2public String reversePrefix(String word, char ch) {3char[] c = word.toCharArray();4int locate = 0;5for (int i = 0; i < word.length(); i++) { // first occurrence of ch6if (ch == c[i]) {7locate = i;8break;9}10}11char[] res = new char[word.length()];12for (int i = 0; i <= locate; i++) {13res[i] = c[locate - i];14}15for (int i = locate + 1; i < word.length(); i++) {16res[i] = c[i];17}18return String.valueOf(res);19}20}