Here you can find the source of startsWithWeight(String s1, String s2)
public static int startsWithWeight(String s1, String s2)
//package com.java2s; /*// ww w.j a v a 2 s . co m * Copyright (C) 2003-2011 eXo Platform SAS. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Return the number of starting letters that s1 and s2 have in common * before they deviate. * * @return the number of starting letters that s1 and s2 have in common * before they deviate */ public static int startsWithWeight(String s1, String s2) { if ((s1 == null) || (s2 == null)) { return 0; } char[] chars1 = s1.toCharArray(); char[] chars2 = s2.toCharArray(); int i = 0; for (; (i < chars1.length) && (i < chars2.length); i++) { if (chars1[i] != chars2[i]) { break; } } return i; } }