看到一个这样子的面试题: 给String对象添加一个方法,传入一个string类型的参数,然后将string的每一个字符间加空格返回,例如:addSpace("hello world") //->'h e l l o w o r l d'. 第一眼看这道题目觉得出的很有问题, 既然给String中添加对象,调用方法应该是str.addSpace(),addSpace(str)是一个普通函数的调用方法吧! 请教了下别人,发现自己思维有点误区,直接就考虑到了给String原型添加对象
代码: public class TestString { String str = new String("good"); char [] ch = {'a','b','c'}; public static void main(String[] args) { // TODO Auto-generated method stub TestString ex = new TestString(); ex.change(ex.str,ex.ch); System.out.println(