Java examples for java.lang:StringBuilder
Does the StringBuilder start with prefix?
/* Copyright 2011 Alexander Bunkenburg alex@inspiracio.com This file is part of atom.jar.// w ww. j a va2s.c o m atom.jar is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. atom.jar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with atom.jar. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { StringBuilder builder = new StringBuilder(); String prefix = "java2s.com"; System.out.println(startsWith(builder, prefix)); } /** Does the builder start with prefix? * @param builder * @param prefix * @return boolean */ public static boolean startsWith(StringBuilder builder, String prefix) { boolean startsWith = builder.indexOf(prefix) == 0; return startsWith; } /** Does the builder start with prefix? * @param builder * @param prefix * @param offset * @return boolean */ public static boolean startsWith(StringBuilder builder, String prefix, int offset) { int i = builder.indexOf(prefix, offset); boolean startsWith = i == offset; return startsWith; } }