本帖最后由 dicmo 于 2010-03-31 19:51:52 编辑

解决方案 »

  1.   

    public class Main {    public static void main(String[] args) throws MalformedURLException, IOException {
            String str = "什么把字符串转化成为字符串数组??";
            char[] ct = str.toCharArray();//符串转化成为字符串数组
            final Gon g = new Gon(ct);
            for (int i = 0; i < 10; i++) {
                new Thread(new Runnable() {                public void run() {
                        while (g.hasNext()) {
                            char c = g.getC();
                            if (g.hasNext()) {
                                System.out.println(Thread.currentThread().getName() + ":" + c);
                            }
                        }
                    }
                }).start();
            }
        }
    }class Gon {    char[] c;
        int po, cou;    Gon(char[] ch) {
            c = ch;
        }    synchronized char getC() {
            try {
                Thread.sleep(1000);//停1000毫秒
            } catch (InterruptedException ex) {
            }
            po++;
            if (po > c.length) {
                return '\0';
            }
            return c[cou++];
        }    boolean hasNext() {
            return po <= c.length;
        }
    }