以下代码将打印出
public static void main (String[] args) { String classFile = "com.jd.". replaceAll(".", "/") + "MyClass.class"; System.out.println(classFile); }
1)replace的参数是char和CharSequence,即可以支持字符的替换,也支持字符串的替换(CharSequence即字符串序列的意思,说白了也就是字符串);
2)replaceAll的参数是regex,即基于规则表达式的替换,比如,可以通过replaceAll("\\d", "*")把一个字符串所有的数字字符都换成星号;
题目中“.”,在正则表达式中表示任何符号,所以答案是C,五个字母,2个点号,两个空格被代替。
/** * Created by jiangxs on 17-5-16. */ public class NowCoder1 { public static void main(String[] args) { String classFile = "com.jd.".replaceAll(".","/")+"MyClass.class"; System.out.println(classFile); } }
///////MyClass.class Process finished with exit code 0还有,题目中的“com.jd.”中并没有空格