看例子练apache commons之lang篇

王朝system·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

看commons包时的相关练习,可以用这个包提高编码效率。

package org.raistlin.test.apache;

import Java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.Calendar;

import java.util.Date;

import java.util.Iterator;

import org.apache.commons.lang.ArrayUtils;

import org.apache.commons.lang.CharSet;

import org.apache.commons.lang.CharSetUtils;

import org.apache.commons.lang.ClassUtils;

import org.apache.commons.lang.ObjectUtils;

import org.apache.commons.lang.RandomStringUtils;

import org.apache.commons.lang.SerializationUtils;

import org.apache.commons.lang.StringEscapeUtils;

import org.apache.commons.lang.StringUtils;

import org.apache.commons.lang.SystemUtils;

import org.apache.commons.lang.builder.EqualsBuilder;

import org.apache.commons.lang.builder.HashCodeBuilder;

import org.apache.commons.lang.builder.ToStringBuilder;

import org.apache.commons.lang.builder.ToStringStyle;

import org.apache.commons.lang.math.NumberUtils;

import org.apache.commons.lang.time.DateFormatUtils;

import org.apache.commons.lang.time.DateUtils;

import org.apache.commons.lang.time.StopWatch;

public class LangDemo

{

public void charSetDemo()

{

System.out.println("**CharSetDemo**");

CharSet charSet = CharSet.getInstance("aeiou");

String demoStr = "The quick brown fox jumps over the lazy dog.";

int count = 0;

for (int i = 0, len = demoStr.length(); i < len; i++)

{

if (charSet.contains(demoStr.charAt(i)))

{

count++;

}

}

System.out.println("count: " + count);

}

public void charSetUtilsDemo()

{

System.out.println("**CharSetUtilsDemo**");

System.out.println("计算字符串中包含某字符数.");

System.out.println(CharSetUtils.count(

"The quick brown fox jumps over the lazy dog.", "aeiou"));

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航