Here you can find the source of substr(String substr1, String substr2)
public static String substr(String substr1, String substr2)
//package com.java2s; public class Main { /** @METHOD */ public static String substr(String substr1, String substr2) { String substr = ""; int size = Math.min(substr1.length(), substr2.length()); for (int i = 0; i < size; i++) { if (substr1.charAt(i) == substr2.charAt(i)) substr += substr1.charAt(i); else//from w w w .j ava2s . c o m break; } return substr; } }