Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26312876
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Java

2010-04-27 22:50:36

public class Test {
    public static void main(String[] args) {
        String a = "localhost:8001";
        int index = a.lastIndexOf(':');
        if (index < 1) {
            throw new IllegalArgumentException("参数异常");
        }
        String host = a.substring(0, index);
        String port = a.substring(index + 1);
        System.out.println(host + "," + port);
    }
}

1. 分割字符串。

2. 分割字符串并保存到ArrayList中

public class T {
    public static void main(String[] args) {
        List notCheckURLList = new ArrayList();
        String a = "a.jsp;b.jsp";
        StringTokenizer st = new StringTokenizer(a, ";");
        while(st.hasMoreTokens()) {
            notCheckURLList.add(st.nextToken());
        }
        for (Iterator iterator = notCheckURLList.iterator(); iterator.hasNext();) {
            String object = (String) iterator.next();
            System.out.println(object);
        }
    }
}


阅读(841) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~