代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
字符串类库
作者:
/ 发布于
2011/1/14
/
484
<div><span style="color: #0000ff">package</span><span style="color: #000000"> net.java2000.tools; </span><span style="color: #008000">/**</span><span style="color: #008000"> * Title: Java Bean 工具 * Description: * Copyright: Copyright (c) 2001 * Company: JAVA世纪网 </span><span style="color: #008000; text-decoration: underline">http://www.java2000.net</span><span style="color: #008000"> * </span><span style="color: #808080">@author</span><span style="color: #008000"> 赵学庆 * </span><span style="color: #808080">@version</span><span style="color: #008000"> 1.0 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.</span><span style="color: #000000">*</span><span style="color: #000000">; </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.regex.Pattern; </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> StrTools { </span><span style="color: #008000">/**</span><span style="color: #008000"> * 分割字符串 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str String 原始字符串 * </span><span style="color: #808080">@param</span><span style="color: #008000"> splitsign String 分隔符 * </span><span style="color: #808080">@return</span><span style="color: #008000"> String[] 分割后的字符串数组 </span><span style="color: #008000">*/</span><span style="color: #000000"> @SuppressWarnings(</span><span style="color: #000000">"</span><span style="color: #000000">unchecked</span><span style="color: #000000">"</span><span style="color: #000000">) </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String[] split(String str, String splitsign) { </span><span style="color: #0000ff">int</span><span style="color: #000000"> index; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> splitsign </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; ArrayList al </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ArrayList(); </span><span style="color: #0000ff">while</span><span style="color: #000000"> ((index </span><span style="color: #000000">=</span><span style="color: #000000"> str.indexOf(splitsign)) </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">) { al.add(str.substring(</span><span style="color: #000000">0</span><span style="color: #000000">, index)); str </span><span style="color: #000000">=</span><span style="color: #000000"> str.substring(index </span><span style="color: #000000">+</span><span style="color: #000000"> splitsign.length()); } al.add(str); </span><span style="color: #0000ff">return</span><span style="color: #000000"> (String[]) al.toArray(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String[</span><span style="color: #000000">0</span><span style="color: #000000">]); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 替换字符串 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> from String 原始字符串 * </span><span style="color: #808080">@param</span><span style="color: #008000"> to String 目标字符串 * </span><span style="color: #808080">@param</span><span style="color: #008000"> source String 母字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> String 替换后的字符串 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String replace(String from, String to, String source) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (source </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> from </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> to </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; StringBuffer bf </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> StringBuffer(</span><span style="color: #000000">""</span><span style="color: #000000">); </span><span style="color: #0000ff">int</span><span style="color: #000000"> index </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">; </span><span style="color: #0000ff">while</span><span style="color: #000000"> ((index </span><span style="color: #000000">=</span><span style="color: #000000"> source.indexOf(from)) </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">) { bf.append(source.substring(</span><span style="color: #000000">0</span><span style="color: #000000">, index) </span><span style="color: #000000">+</span><span style="color: #000000"> to); source </span><span style="color: #000000">=</span><span style="color: #000000"> source.substring(index </span><span style="color: #000000">+</span><span style="color: #000000"> from.length()); index </span><span style="color: #000000">=</span><span style="color: #000000"> source.indexOf(from); } bf.append(source); </span><span style="color: #0000ff">return</span><span style="color: #000000"> bf.toString(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 替换字符串,能能够在HTML页面上直接显示(替换双引号和小于号) * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str String 原始字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> String 替换后的字符串 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String htmlencode(String str) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000">\"</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">"</span><span style="color: #000000">"</span><span style="color: #000000">, replace(</span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, str)); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 替换字符串,将被编码的转换成原始码(替换成双引号和小于号) * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str String * </span><span style="color: #808080">@return</span><span style="color: #008000"> String </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String htmldecode(String str) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000">"</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">\"</span><span style="color: #000000">"</span><span style="color: #000000">, replace(</span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, str)); } </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">final</span><span style="color: #000000"> String _BR </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"><br/></span><span style="color: #000000">"</span><span style="color: #000000">; </span><span style="color: #008000">/**</span><span style="color: #008000"> * 在页面上直接显示文本内容,替换小于号,空格,回车,TAB * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str String 原始字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> String 替换后的字符串 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String htmlshow(String str) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; } str </span><span style="color: #000000">=</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000"><</span><span style="color: #000000">"</span><span style="color: #000000">, str); str </span><span style="color: #000000">=</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">, str); str </span><span style="color: #000000">=</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000">\r\n</span><span style="color: #000000">"</span><span style="color: #000000">, _BR, str); str </span><span style="color: #000000">=</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">, _BR, str); str </span><span style="color: #000000">=</span><span style="color: #000000"> replace(</span><span style="color: #000000">"</span><span style="color: #000000">\t</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">, str); </span><span style="color: #0000ff">return</span><span style="color: #000000"> str; } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 返回指定字节长度的字符串 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str String 字符串 * </span><span style="color: #808080">@param</span><span style="color: #008000"> length int 指定长度 * </span><span style="color: #808080">@return</span><span style="color: #008000"> String 返回的字符串 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String toLength(String str, </span><span style="color: #0000ff">int</span><span style="color: #000000"> length) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">; } </span><span style="color: #0000ff">if</span><span style="color: #000000"> (length </span><span style="color: #000000"><=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">""</span><span style="color: #000000">; } </span><span style="color: #0000ff">try</span><span style="color: #000000"> { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str.getBytes(</span><span style="color: #000000">"</span><span style="color: #000000">GBK</span><span style="color: #000000">"</span><span style="color: #000000">).length </span><span style="color: #000000"><=</span><span style="color: #000000"> length) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> str; } } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (Exception ex) { } StringBuffer buff </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> StringBuffer(); </span><span style="color: #0000ff">int</span><span style="color: #000000"> index </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; </span><span style="color: #0000ff">char</span><span style="color: #000000"> c; length </span><span style="color: #000000">-=</span><span style="color: #000000"> </span><span style="color: #000000">3</span><span style="color: #000000">; </span><span style="color: #0000ff">while</span><span style="color: #000000"> (length </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { c </span><span style="color: #000000">=</span><span style="color: #000000"> str.charAt(index); </span><span style="color: #0000ff">if</span><span style="color: #000000"> (c </span><span style="color: #000000"><</span><span style="color: #000000"> </span><span style="color: #000000">128</span><span style="color: #000000">) { length</span><span style="color: #000000">--</span><span style="color: #000000">; } </span><span style="color: #0000ff">else</span><span style="color: #000000"> { length</span><span style="color: #000000">--</span><span style="color: #000000">; length</span><span style="color: #000000">--</span><span style="color: #000000">; } buff.append(c); index</span><span style="color: #000000">++</span><span style="color: #000000">; } buff.append(</span><span style="color: #000000">"</span><span style="color: #000000">...</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> buff.toString(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 判断是否为整数 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str 传入的字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> 是整数返回true,否则返回false </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isInteger(String str) { Pattern pattern </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(</span><span style="color: #000000">"</span><span style="color: #000000">^[-\\+]?[\\d]*$</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> pattern.matcher(str).matches(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 判断是否为浮点数,包括double和float * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str 传入的字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> 是浮点数返回true,否则返回false </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isDouble(String str) { Pattern pattern </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(</span><span style="color: #000000">"</span><span style="color: #000000">^[-\\+]?[.\\d]*$</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> pattern.matcher(str).matches(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 判断输入的字符串是否符合Email样式. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str 传入的字符串 * </span><span style="color: #808080">@return</span><span style="color: #008000"> 是Email样式返回true,否则返回false </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isEmail(String str) { Pattern pattern </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(</span><span style="color: #000000">"</span><span style="color: #000000">^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> pattern.matcher(str).matches(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 判断输入的字符串是否为纯汉字 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str 传入的字符窜 * </span><span style="color: #808080">@return</span><span style="color: #008000"> 如果是纯汉字返回true,否则返回false </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isChinese(String str) { Pattern pattern </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(</span><span style="color: #000000">"</span><span style="color: #000000">[\u0391-\uFFE5]+$</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> pattern.matcher(str).matches(); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 是否为空白,包括null和"" * * </span><span style="color: #808080">@param</span><span style="color: #008000"> str * </span><span style="color: #808080">@return</span><span style="color: #008000"> </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isBlank(String str) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> str </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> str.trim().length() </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; } </span><span style="color: #008000">/**</span><span style="color: #008000"> * 判断是否为质数 * * </span><span style="color: #808080">@param</span><span style="color: #008000"> x * </span><span style="color: #808080">@return</span><span style="color: #008000"> </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> isPrime(</span><span style="color: #0000ff">int</span><span style="color: #000000"> x) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000"><=</span><span style="color: #000000"> </span><span style="color: #000000">7</span><span style="color: #000000">) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> x </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">3</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> x </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">5</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> x </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">7</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">; } </span><span style="color: #0000ff">int</span><span style="color: #000000"> c </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">7</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000"> </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> </span><span style="color: #000000">3</span><span style="color: #000000"> </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> </span><span style="color: #000000">5</span><span style="color: #000000"> </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; </span><span style="color: #0000ff">int</span><span style="color: #000000"> end </span><span style="color: #000000">=</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000">) Math.sqrt(x); </span><span style="color: #0000ff">while</span><span style="color: #000000"> (c </span><span style="color: #000000"><=</span><span style="color: #000000"> end) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">4</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">4</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">4</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">6</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (x </span><span style="color: #000000">%</span><span style="color: #000000"> c </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; } c </span><span style="color: #000000">+=</span><span style="color: #000000"> </span><span style="color: #000000">6</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">; } </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) { String[] numbers </span><span style="color: #000000">=</span><span style="color: #000000"> { </span><span style="color: #000000">"</span><span style="color: #000000">12345</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">-12345</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">123.45</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">-123.45</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">.12345</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">-.12345</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">a12345</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">12345a</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">123.a45</span><span style="color: #000000">"</span><span style="color: #000000"> }; </span><span style="color: #0000ff">for</span><span style="color: #000000"> (String str : numbers) { System.out.println(str </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> isInteger(str) </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> isDouble(str)); } String[] emails </span><span style="color: #000000">=</span><span style="color: #000000"> { </span><span style="color: #000000">"</span><span style="color: #000000">1@2.com</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">1.2@3.com</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">1@3.4.5.com</span><span style="color: #000000">"</span><span style="color: #000000"> }; </span><span style="color: #0000ff">for</span><span style="color: #000000"> (String str : emails) { System.out.println(str </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> isEmail(str)); } String[] chineses </span><span style="color: #000000">=</span><span style="color: #000000"> { </span><span style="color: #000000">"</span><span style="color: #000000">中国</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">1中国</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">中国1</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">1中国2</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">中1国</span><span style="color: #000000">"</span><span style="color: #000000"> }; </span><span style="color: #0000ff">for</span><span style="color: #000000"> (String str : chineses) { System.out.println(str </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> isChinese(str)); } } }</span> </div>
试试其它关键字
字符串类库
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3