package com.niu.utils;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;
import com.niu.common.Const;
public class StringUtils {
private static StringUtils instance = new StringUtils();
private StringUtils() {
}
public static StringUtils getInstance() {
return instance;
}
/**
* @param languageType
* @return parseLanguage
*/
public ResourceBundle parseLanguage(String languageType) {
ResourceBundle rb = null;
if ((Const.LANGUAGE_TYPE_CHINA).equals(languageType)) {
rb = ResourceBundle.getBundle(Const.LANGUAGE_FILE_PATH,
Locale.CHINA);
} else if ((Const.LANGUAGE_TYPE_US).equals(languageType)) {
rb = ResourceBundle.getBundle(Const.LANGUAGE_FILE_PATH, Locale.US);
} else {
throw new IllegalArgumentException(languageType + "illegal!");
}
return rb;
}
/**
* @param languageType
* @param propertyKey
* @return getPropertyValue
*/
public String getPropertyValue(String languageType, String propertyKey) {
return this.parseLanguage(languageType).getString(propertyKey);
}
/**
* @param i
* @param str
* @return
*/
public String getStrByByte(int i, String str) {
String result = "";
for (;;) {
if (str.isEmpty()
|| (result + str.substring(0, 1)).getBytes().length > i) {
break;
}
result = result + str.substring(0, 1);
str = str.substring(1);
}
return result;
}
/**
* @param str
* @return
*/
public Map<character integer> countCharCnt(String str) {
Map<character integer> map = new HashMap<character integer>();
char[] chrs = str.toCharArray();
for (char ch : chrs) {
if (map.containsKey(ch)) {
int count = map.get(ch);
map.put(ch, ++count);
} else {
map.put(ch, 1);
}
}
return map;
}
/**
* @param src
* @param index
* @return
*/
public String[] getLoopArray(String[] src, int index) {
String[] dest = new String[src.length];
;
for (int i = 0; i = src.length) {
dest[i + index - src.length] = src[i];
} else {
dest[i + index] = src[i];
}
}
return dest;
}
public Set<string> getChar2SubStred(String src) {
Set<string> set = new HashSet<string>();
//子串长度
for(int i=1;i<src.length for index="0;index&lt;src.length()-index;index++)" set.add return set o printobject public void print system.out.println obj : system.out.print map integer> map) {
// for (Character o : map.keySet()) {
// System.out.println("key: " + o + " value: " + map.get(o));
// }
Set<entry integer>&gt; entrySet = map.entrySet();
for (Entry<character integer> entry : entrySet) {
System.out.println("key: " + entry.getKey() + " value: "
+ entry.getValue());
}
}
public void print(Collection<object> c) {
for (Object o : c) {
System.out.println(o);
}
}
public static void main(String[] args) {
StringUtils s = StringUtils.getInstance();
s.print(s
.getPropertyValue(Const.LANGUAGE_TYPE_US, Const.LOGIN_USERNAME));
s.print(s.getPropertyValue(Const.LANGUAGE_TYPE_CHINA,
Const.LOGIN_USERNAME));
s.print(s.getStrByByte(7, "abc中国"));
s.print(s.countCharCnt("aabbcddd"));
s.print(s.getLoopArray(new String[] { "a", "b", "c" }, 2));
s.print(s.getChar2SubStred("abab"));
}
}
----------------------------------------------------------------------------------------------map 统计字符/单词个数-----------------------------------------------------
/**
* map char count
*
* @param str
* @return
*/
public Map<character integer> getCharCnt(String str) {
char[] chrs = str.toCharArray();
Map<character integer> map = new HashMap<character integer>();
for (char ch : chrs) {
if (map.containsKey(ch)) {
int count = map.get(ch);
map.put(ch, ++count);
} else {
map.put(ch, 1);
}
}
return map;
}
/**
* map word cnt
*
* @param strs
* @return
*/
public Map<string integer> getWordCnt(String[] strs) {
Map<string integer> map = new HashMap<string integer>();
for (String str : strs) {
if (map.containsKey(str)) {
int count = map.get(str);
map.put(str, ++count);
} else {
map.put(str, 1);
}
}
return map;
}
/**
* map keySet
*
* @param map
*/
public void printMapkeySet(Map, ?&gt; map) {
for (Object o : map.keySet()) {
System.out.println("key: " + o + " " + "value: " + map.get(o));
}
}
/**
* map entrySet
*
* @param map
*/
public void printMapEntrySet(Map<character integer> map) {
Set<entry integer>&gt; entrySet = map.entrySet();
for (Entry<character integer> entry : entrySet) {
System.out.println("key: " + entry.getKey() + " " + "value: "
+ entry.getValue());
}
}
public void print(Object o) {
System.out.println(o);
}
private static StringUtil instance = new StringUtil();
private StringUtil() {
}
public static StringUtil getInstance() {
return instance;
}
public void isvalidStr(String str) {
}
/**
* about word.....replace
*
* @param str
* @return
*/
public String getSplitWord(String str) {
if (str == null) {
throw new NullPointerException();
}
if (str.isEmpty()) {
return "";
}
if (!str.matches("^[a-zA-Z,。 ]+$")) {
throw new IllegalArgumentException();
}
StringBuffer msg = new StringBuffer("");
String[] strs = str.replaceAll(",", " ").replaceAll("。", " ")
.split("\\W");
for (String s : strs) {
msg = msg.append(s);
}
return msg.toString();
}
public String[] getSplitWordArray(String str) {
if (str == null) {
throw new NullPointerException();
}
if (str.isEmpty()) {
return new String[] { "" };
}
if (!str.matches("^[a-zA-Z,。 ]{1,}")) {
throw new IllegalArgumentException();
}
return str.replaceAll(",", " ").replaceAll("。", " ").split("\\W");
}
-------------------------------------------------------------------------------string,stringBuffer,StringBuilder---------------------------------------------------------------------------
/**
* string,stringBuffer,stringBuilder性能比较
* 数据较小时用StringBuffer
* 数据庞大时用StringBuilder
*
* @return
*/
public long getTimeString() {
String str = "";
long start = System.currentTimeMillis();
for (int i = 0; i = 0;
}
/**
* is letter
*
* @param ch
* @return
*/
public boolean isLetter(char ch) {
return "abcdefjhijklmnopqrstuvwsyz".indexOf(ch) &gt;= 0;
}
----------------------------------------------------------------------------DBUtils------------------------------------------------------------------------------------
package com.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
public class DBUtil {
private Connection conn = null;
private PreparedStatement ps = null;
private ResultSet rs = null;
private static final String DB_FILE_PATH = "demo_db";
private static String drive;
private static String url;
private static String username;
private static String password;
static {
ResourceBundle resb = ResourceBundle.getBundle(DB_FILE_PATH);
drive = resb.getString("DRIVERS").trim();
url = resb.getString("URL").trim();
username = resb.getString("USER").trim();
password = resb.getString("PASSWORD").trim();
}
private static DBUtil instance = new DBUtil();
private DBUtil() {
}
public static DBUtil getInstance() {
return instance;
}
public Connection getConnection() {
try {
Class.forName(drive);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void insert(String sql) {
try {
conn = this.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1, 1);
ps.setString(2, "");
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.close(ps);
this.close(conn);
}
}
public void update(String sql) {
try {
conn = this.getConnection();
ps = conn.prepareStatement(sql);
ps.setString(1, "");
rs = ps.executeQuery();
while (rs.next()) {
rs.getString("");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.close(rs);
this.close(ps);
this.close(conn);
}
}
public void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(Statement ps) {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
----------------------------------------字节判断-----------------------
* 1:a
* 3: abc
* 5: abc中
* 6:abc中
* 7:abc中国
* @version
*/
public String getStringByBytes(int num,String sourceStr){
String destStr = "";
for(;;){
if((destStr+sourceStr.substring(0,1)).getBytes().length &gt; num){
break;
}
destStr = destStr+sourceStr.substring(0,1);
sourceStr = sourceStr.substring(1);
}
return destStr;
} </character></entry></character></string></string></string></character></character></character></object></character></entry></src.length></string></string></string></character></character></character>
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;
import com.niu.common.Const;
public class StringUtils {
private static StringUtils instance = new StringUtils();
private StringUtils() {
}
public static StringUtils getInstance() {
return instance;
}
/**
* @param languageType
* @return parseLanguage
*/
public ResourceBundle parseLanguage(String languageType) {
ResourceBundle rb = null;
if ((Const.LANGUAGE_TYPE_CHINA).equals(languageType)) {
rb = ResourceBundle.getBundle(Const.LANGUAGE_FILE_PATH,
Locale.CHINA);
} else if ((Const.LANGUAGE_TYPE_US).equals(languageType)) {
rb = ResourceBundle.getBundle(Const.LANGUAGE_FILE_PATH, Locale.US);
} else {
throw new IllegalArgumentException(languageType + "illegal!");
}
return rb;
}
/**
* @param languageType
* @param propertyKey
* @return getPropertyValue
*/
public String getPropertyValue(String languageType, String propertyKey) {
return this.parseLanguage(languageType).getString(propertyKey);
}
/**
* @param i
* @param str
* @return
*/
public String getStrByByte(int i, String str) {
String result = "";
for (;;) {
if (str.isEmpty()
|| (result + str.substring(0, 1)).getBytes().length > i) {
break;
}
result = result + str.substring(0, 1);
str = str.substring(1);
}
return result;
}
/**
* @param str
* @return
*/
public Map<character integer> countCharCnt(String str) {
Map<character integer> map = new HashMap<character integer>();
char[] chrs = str.toCharArray();
for (char ch : chrs) {
if (map.containsKey(ch)) {
int count = map.get(ch);
map.put(ch, ++count);
} else {
map.put(ch, 1);
}
}
return map;
}
/**
* @param src
* @param index
* @return
*/
public String[] getLoopArray(String[] src, int index) {
String[] dest = new String[src.length];
;
for (int i = 0; i = src.length) {
dest[i + index - src.length] = src[i];
} else {
dest[i + index] = src[i];
}
}
return dest;
}
public Set<string> getChar2SubStred(String src) {
Set<string> set = new HashSet<string>();
//子串长度
for(int i=1;i<src.length for index="0;index&lt;src.length()-index;index++)" set.add return set o printobject public void print system.out.println obj : system.out.print map integer> map) {
// for (Character o : map.keySet()) {
// System.out.println("key: " + o + " value: " + map.get(o));
// }
Set<entry integer>&gt; entrySet = map.entrySet();
for (Entry<character integer> entry : entrySet) {
System.out.println("key: " + entry.getKey() + " value: "
+ entry.getValue());
}
}
public void print(Collection<object> c) {
for (Object o : c) {
System.out.println(o);
}
}
public static void main(String[] args) {
StringUtils s = StringUtils.getInstance();
s.print(s
.getPropertyValue(Const.LANGUAGE_TYPE_US, Const.LOGIN_USERNAME));
s.print(s.getPropertyValue(Const.LANGUAGE_TYPE_CHINA,
Const.LOGIN_USERNAME));
s.print(s.getStrByByte(7, "abc中国"));
s.print(s.countCharCnt("aabbcddd"));
s.print(s.getLoopArray(new String[] { "a", "b", "c" }, 2));
s.print(s.getChar2SubStred("abab"));
}
}
----------------------------------------------------------------------------------------------map 统计字符/单词个数-----------------------------------------------------
/**
* map char count
*
* @param str
* @return
*/
public Map<character integer> getCharCnt(String str) {
char[] chrs = str.toCharArray();
Map<character integer> map = new HashMap<character integer>();
for (char ch : chrs) {
if (map.containsKey(ch)) {
int count = map.get(ch);
map.put(ch, ++count);
} else {
map.put(ch, 1);
}
}
return map;
}
/**
* map word cnt
*
* @param strs
* @return
*/
public Map<string integer> getWordCnt(String[] strs) {
Map<string integer> map = new HashMap<string integer>();
for (String str : strs) {
if (map.containsKey(str)) {
int count = map.get(str);
map.put(str, ++count);
} else {
map.put(str, 1);
}
}
return map;
}
/**
* map keySet
*
* @param map
*/
public void printMapkeySet(Map, ?&gt; map) {
for (Object o : map.keySet()) {
System.out.println("key: " + o + " " + "value: " + map.get(o));
}
}
/**
* map entrySet
*
* @param map
*/
public void printMapEntrySet(Map<character integer> map) {
Set<entry integer>&gt; entrySet = map.entrySet();
for (Entry<character integer> entry : entrySet) {
System.out.println("key: " + entry.getKey() + " " + "value: "
+ entry.getValue());
}
}
public void print(Object o) {
System.out.println(o);
}
private static StringUtil instance = new StringUtil();
private StringUtil() {
}
public static StringUtil getInstance() {
return instance;
}
public void isvalidStr(String str) {
}
/**
* about word.....replace
*
* @param str
* @return
*/
public String getSplitWord(String str) {
if (str == null) {
throw new NullPointerException();
}
if (str.isEmpty()) {
return "";
}
if (!str.matches("^[a-zA-Z,。 ]+$")) {
throw new IllegalArgumentException();
}
StringBuffer msg = new StringBuffer("");
String[] strs = str.replaceAll(",", " ").replaceAll("。", " ")
.split("\\W");
for (String s : strs) {
msg = msg.append(s);
}
return msg.toString();
}
public String[] getSplitWordArray(String str) {
if (str == null) {
throw new NullPointerException();
}
if (str.isEmpty()) {
return new String[] { "" };
}
if (!str.matches("^[a-zA-Z,。 ]{1,}")) {
throw new IllegalArgumentException();
}
return str.replaceAll(",", " ").replaceAll("。", " ").split("\\W");
}
-------------------------------------------------------------------------------string,stringBuffer,StringBuilder---------------------------------------------------------------------------
/**
* string,stringBuffer,stringBuilder性能比较
* 数据较小时用StringBuffer
* 数据庞大时用StringBuilder
*
* @return
*/
public long getTimeString() {
String str = "";
long start = System.currentTimeMillis();
for (int i = 0; i = 0;
}
/**
* is letter
*
* @param ch
* @return
*/
public boolean isLetter(char ch) {
return "abcdefjhijklmnopqrstuvwsyz".indexOf(ch) &gt;= 0;
}
----------------------------------------------------------------------------DBUtils------------------------------------------------------------------------------------
package com.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
public class DBUtil {
private Connection conn = null;
private PreparedStatement ps = null;
private ResultSet rs = null;
private static final String DB_FILE_PATH = "demo_db";
private static String drive;
private static String url;
private static String username;
private static String password;
static {
ResourceBundle resb = ResourceBundle.getBundle(DB_FILE_PATH);
drive = resb.getString("DRIVERS").trim();
url = resb.getString("URL").trim();
username = resb.getString("USER").trim();
password = resb.getString("PASSWORD").trim();
}
private static DBUtil instance = new DBUtil();
private DBUtil() {
}
public static DBUtil getInstance() {
return instance;
}
public Connection getConnection() {
try {
Class.forName(drive);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void insert(String sql) {
try {
conn = this.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1, 1);
ps.setString(2, "");
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.close(ps);
this.close(conn);
}
}
public void update(String sql) {
try {
conn = this.getConnection();
ps = conn.prepareStatement(sql);
ps.setString(1, "");
rs = ps.executeQuery();
while (rs.next()) {
rs.getString("");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.close(rs);
this.close(ps);
this.close(conn);
}
}
public void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(Statement ps) {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
----------------------------------------字节判断-----------------------
* 1:a
* 3: abc
* 5: abc中
* 6:abc中
* 7:abc中国
* @version
*/
public String getStringByBytes(int num,String sourceStr){
String destStr = "";
for(;;){
if((destStr+sourceStr.substring(0,1)).getBytes().length &gt; num){
break;
}
destStr = destStr+sourceStr.substring(0,1);
sourceStr = sourceStr.substring(1);
}
return destStr;
} </character></entry></character></string></string></string></character></character></character></object></character></entry></src.length></string></string></string></character></character></character>
- 016_机试试题.rar (10.4 KB)
- 下载次数: 0
发表评论
-
线程总结
2013-03-01 15:08 0什么是线程? 运行在操 ... -
网络总结
2013-03-01 15:07 0网络就是一种连接在一起的计算机。 使用网卡、电缆、集线器等连接 ... -
正则表达式
2012-10-25 13:57 547String str = "90";//2 ... -
内存溢出和内存泄露
2012-10-23 10:07 609内存泄露: 内存泄漏也称作“存储渗漏”,用动态存储分 ... -
java基础知识
2012-10-22 18:47 561集合类 http://blog.csdn.net/allen_ ... -
java sort
2012-10-22 18:43 836一:Arrays.sort(int[] a ) 二:Coll ... -
详解Java解析XML的四种方法
2012-10-09 13:13 533XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言 ... -
apache common-lang
2012-10-08 19:24 761public static int countMa ... -
Java中对文件的操作
2012-09-27 19:44 530java中提供了io类库,可以轻松的用java实 ... -
StringUtil一些字符串的处理方法
2012-09-24 10:04 869public class StringUtil{ publi ... -
java 创建xml和解析xml
2012-09-24 10:00 560import java.io.FileWriter;impo ... -
map的4中遍历方式(第二种好)
2012-09-24 09:59 642import java.util.HashMap; impor ... -
创建线程两种方式
2012-09-24 09:59 755public class T1 extends Thread ... -
java 文件遍历
2012-09-15 16:43 1020/** * 功能: * 1.获取D盘下2级范围所有的文 ... -
经典题目
2012-09-15 16:42 597a. 随机产生2位到10位不等的并且只包含和必须 ... -
entrySet 和keySet
2012-09-15 16:33 747public class MapList { public ...
相关推荐
Discuz! X2.5新版本推出四大新体系:新社区形态、新技术体系、新门户系统以及新移动化体验,其中新门户系统主要从内容推送、图片裁切、模块管理等角度进行了深度优化,拟帮助站长和编辑更加省时省力地运维网站,提高...
Discuz! X2.5新版本推出四大新体系:新社区形态、新技术体系、新门户系统以及新移动化体验,其中新门户系统主要从内容推送、图片裁切、模块管理等角度进行了深度优化,拟帮助站长和编辑更加省时省力地运维网站,提高...
这个驱动包版本为v4.1.4_6773.20130222,意味着它是2013年2月22日发布的一个稳定版。在Linux环境中,正确安装并配置rtl8188eus驱动对于确保RTL8188EU无线网卡的正常工作至关重要。 Realtek RTL8188EU是一款常见的...
rtl8188EUS_linux_v4.1.4_6773.20130222.tar.gz RTLl8188EU,RTLl8188EUS方案WIFI的linux驱动源码。 找了好久,终于在国外网站发现了,CSDN第一份。
最新VisualAssistX10.7.1929破解版2013-2-22 Visual Assist X 10.7.1929编程助手 内置crack破解工具,win7等系统,需要用管理员身份运行破解
X2.5 正式版 build 20130222更新记录: IX 由于部分变量过滤不严导致的XSS问题 FIX 管理员在版块前台管理面板中更新推荐主题时,原主题推荐者ID被修改为管理员ID的问题(14039) FIX soso表情更换新域名
标题“RTL8188EUS_linux_v4.1.4_6773.20130222”表明这是一个针对Linux操作系统的驱动程序更新,专门设计用于RTL8188EUS无线网卡芯片。RTL8188EUS是一款常见的USB无线网络适配器芯片,由Realtek半导体公司制造。这个...
rtl8188eu驱动源码是用于支持Realtek公司生产的RTL8188EU无线网卡芯片的开源驱动程序。这个驱动对于Linux操作系统尤为重要,因为它允许系统识别并正确操作这款无线网络适配器,从而实现无线网络连接。...
20130222更新: 1、全面升级Kindetior编辑器 2、编辑兼容火狐,360浏览器器 系统操作说明: 域名/admin/admin_login.asp 帐号:admin 管理密码:123456 配置文件/include/config.asp 数据文件/include/conn.asp...
3. "20130222" - 这个文件名可能是日期格式,可能代表源码的创建或更新日期,也可能是某种特定版本的标识。具体含义需要根据上下文来确定,可能与源码的发布或更新有关。 综上所述,这个压缩包提供了一个先进的音乐...
20130222更新: 1、全面升级Kindetior编辑器 2、编辑兼容火狐,360浏览器器 20130120更新: 1、新增后台登陆日志 2、安全加载SQL防注 3、底部列表显示整理 20121220更新: 1、首页页面优化显示 2、关于我们优化显示 ...
在提供的"20130222"文件中,可能包含了实现以上功能的代码示例和相关文档。通过学习和理解这些代码,开发者可以更好地掌握STM32串口通信、IO中断和GPIO控制的核心概念,并应用于实际项目中。在深入研究时,还应关注...
- **文档编号**:RD_OA_0222_《需求分析报告》V1.0_20130222 - **版本号**:V1.0 - **调研目的**:通过对瑞德集团及其下属机构的调研,收集OA系统需求,确保后续开发工作符合集团实际需求。 #### 二、调研概述 - **...