zoukankan      html  css  js  c++  java
  • 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;
        }



  • 相关阅读:
    SpringBoot整合dubbo2.7.12
    linux安装zookeeper
    javaassist创建对象
    jmeter websocket
    jmeter使用
    jmeter返回值乱码
    HTTP 头 Connection:close 作用 和 解决服务器产生大量close_wait问题
    服务器TCP连接中 TIME_WAIT 状态过多
    Chrome 浏览器远程调试 【转】
    拼多多聊天记录监控、拼多多客服机器人代码、拼多多智能机器人代码、拼多多自动发货、拼多多虚拟卡号自动发货
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6937509.html
Copyright © 2011-2022 走看看