### Question:
HtmlUtils { public static String getHeadStr(String html) { char[] chars = html.toCharArray(); boolean isStartTag = true; int startIndex = -1, endIndex = -1; for (int i = 0; i < chars.length; i++) { if (chars[i] == '<' && i < chars.length - 1) { if (isStartTag) { int keyIndex = 0; for (int j = i + 1; j < chars.length; j++) { if (keyIndex == 0 && chars[j] == ' ') { continue; } else if (keyIndex == 4 && chars[j] == ' ') { continue; } if (chars[j] == KEYWORDS[keyIndex]) { keyIndex++; if (keyIndex == 5) { isStartTag = false; startIndex = i; break; } } else { break; } } } else if (chars[i + 1] == '/') { int keyIndex = 0; for (int j = i + 2; j < chars.length; j++) { if (keyIndex == 0 && chars[j] == ' ') { continue; } else if ((keyIndex == 4) && chars[j] == ' ') { continue; } if (chars[j] == KEYWORDS[keyIndex]) { keyIndex++; if (keyIndex == 5) { endIndex = j + 1; break; } } } } } } if (startIndex != -1 && endIndex != -1) { return html.substring(startIndex, endIndex); } return null; }  static String getHtmlCharset(byte[] htmlContent); static String getHtmlCharset(byte[] htmlContent, String defaultCharset); static String getHeadStr(String html);  }### Answer:
@Test public void testGetHtmlHead() { String head = "<head > adwadefe</head >"; String html = "<html>" + head + "<body> dwfrewg</body></html>"; String headStr = HtmlUtils.getHeadStr(html); Assert.assertEquals(head, headStr); }