String 经常用法最优算法实现总结 (一)
<pre name="code" class="java"><span style="font-family: Arial, Helvetica, sans-serif;"></pre><p>1. reverse</p><p><pre name="code" class="java"> /**</span>
* @Description: reverse a string.
* @param str the String to reverse, may be null
* @return reversedStr the reversed String, null if null String input
*/
public static String reverse(String str) {
if (isEmpty(str)) {
return str;
} return new StringBuilder(str).reverse().toString();
}
2 . remove
/**
* @Description: Removes all occurrences of a substring from within the source string.
* @param str the source String to search
* @param remove the String to search for and remove
* @return the substring with the string removed if found, null if null String input
*/
public static String remove(String str, String remove) {
if (isEmpty(str) || isEmpty(remove)) {
return str;
} return str.replace(remove, "");
}
3. startsWithIgnoreCase
/**
*
* @Title: startsWithIgnoreCase
* @Description: check if a string starts with a specified prefix.
* @param str input value
* @param prefix prefix value
* @return true if the string starts with the prefix, case insensitive, or both null, blank
*/
public static boolean startsWithIgnoreCase(String str, String prefix) {
if (str == null || prefix == null) {
return (str == null && prefix == null);
} if (prefix.length() > str.length()) {
return false;
} return str.toUpperCase().startsWith(prefix.toUpperCase());
}
4. isAllAlphas
/**
* whether value does not contain number(s).
*
* @Title: isAllAlphas
* @param value the source to be handled
* @return boolean
*/
public static boolean isAllAlphas(String value) {
// if input parameter is null, just return
if (value == null) {
return false;
} for (int i = 0; i < value.length(); i++) {
if (!(Character.isLetter(value.charAt(i)))) {
return false;
}
} return true;
}
5. isNumeric
/**
* check if the CharSequence contains only unicode digits.
*
* @Title: isNumber
* @param str input str
* @return true or false
*/
public static boolean isNumeric(String str) {
// if input parameter is null, just return false
if (isEmpty(str)) {
return false;
} for (int i = 0; i < str.length(); i++) {
// if there is a alpha, return false
if (!Character.isDigit(str.charAt(i))) {
return false;
}
} return true;
}
String 经常用法最优算法实现总结 (一)的更多相关文章
- String 经常用法最优算法实现总结 (二)
1. String getOrderedString(boolean isDuplicated, String - str) 说明: Orders all characters in the inpu ...
- C#中string.format用法详解
C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...
- String.format()用法
package junit.test; import java.util.Date; import java.util.Locale; import org.junit.Test; pub ...
- java中String的用法
String的用法很活跃,也用到的很多.可以根据自己的需要查询API.这里只有concat和substring,indexof的用法 class TestString { public static ...
- C#中string.Format 用法详解
这篇文章主要介绍了C#中string.format用法,以实例形式较为详细的讲述了string.format格式化的各种用法,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中string. ...
- Oracle中dbms_random.string 的用法
转载:https://blog.csdn.net/simonchi/article/details/8657787 DBMS_RANDOM.STRING(var1,var2) 这个函数有两个参数 va ...
- 关于java中String的用法
在java 中String存在许多的基本函数,接下来了解一下这些函数的基本用法 String.equals用法(这个用法比较难) String类中的equals()方法: public boolean ...
- java成神之——java中string的用法
java中String的用法 String基本用法 String分割 String拼接 String截取 String换行符和format格式化 String反转字符串和去除空白字符 String获取 ...
- string.join用法
C# String.Join用法 String.Join(String, String[]) 在指定 String 数组的每个元素之间串联指定的分隔符 String,从而产生单个串联的字符串 例如: ...
随机推荐
- 关于form/input 的autocomplete="off"属性
转自:http://blog.sina.com.cn/s/blog_b49f96a701019m0d.html 一. 有过表单设计经验的朋友肯定知道,当我们在浏览器中输入表单信息的时候,往往input ...
- Webpack 2.0 的文档
Webpack 2.0 的文档 https://webpack.js.org/get-started/
- Oracle Instant Client 安装配置
一.下载 下载地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html 这是Ora ...
- BN 详解和使用Tensorflow实现(参数理解)
Tensorflow BN具体实现(多种方式): 理论知识(参照大佬):https://blog.csdn.net/hjimce/article/details/50866313 补充知识: ① ...
- [转载]cocos2d-触摸分发原理
本文由泰然翻译组组长 TXX_糖炒小虾 原创,版权所有,转载请注明出处并通知作者和泰然! 原作 http://www.ityran.com/archives/1326/comment-page-1 触 ...
- pgsql 远程机器无法连接数据库报错处理方法
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本地localhost访问正常,在相同网段的远程机器访问报如下错误 “server closed the connection unexpe ...
- react中withRouter解决props返回为空
利用 react + antd 框架书写导航栏时,遇到了几个坑,分别是一级菜单和二级菜单在点击的情况下,高亮没有任何问题,但是再点击浏览器返回按钮时,却就乱套了. 1. 二级菜单中,我们可以通过 pr ...
- python--7、面向对象
什么是面向对象 对象,即抽象的一类事物中的某个具体的个体.这个世界中存在的一切皆为对象,不存在的也能创建出来. 较之面向过程的区别: 编程的复杂度远高于面向过程,不了解面向对象而立即上手基于它设计程序 ...
- AI: DL方法与问题空间探索
所谓问题的解决是生存参数空间的一种状态转移到另外一种状态,而目的状态恰好是主体所希望的.完成这种转换的一系列脚本变化过程叫做场景序列,也叫通路.驱动这一些列场景转换的主体参与过程,被称为主动执行.而主 ...
- 读书笔记「Python编程:从入门到实践」_8.函数
8.1 定义函数 def greet_user(): # def 来告诉Python你要定义一个函数.这是函数定义 """Hello World""& ...