zoukankan      html  css  js  c++  java
  • java--CharAt,StartWith

    public class CharAtStartWithDemo {
        public static void main(String[] args){
            //jdk8
            testCharAt();//1
            testStartWith();//4
        }
        public static void testCharAt(){
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < 1000; i++) {
                sb.append(i);
                if (i < 999){
                    sb.append(",");
                }
            }
            String s = sb.toString();
            int length = s.length();
            long begin = System.currentTimeMillis();
            for (int i = 0; i < 10000; i++) {
                if (s.charAt(0)=='a'&&s.charAt(1)=='b'&&s.charAt(2)=='c'){}
                if (s.charAt(length-1)=='a'&&s.charAt(length-2)=='b'&&s.charAt(length-3)=='c'){}
            }
            long end = System.currentTimeMillis();
            System.out.println(end-begin);
        }
        public static void testStartWith(){
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < 1000; i++) {
                sb.append(i);
                if (i < 999){
                    sb.append(",");
                }
            }
            String s = sb.toString();
            int length = s.length();
            long begin = System.currentTimeMillis();
            for (int i = 0; i < 10000; i++) {
                if (s.startsWith("abc")){}
                if (s.endsWith("abc")){}
            }
            long end = System.currentTimeMillis();
            System.out.println(end-begin);
        }
    }
    
  • 相关阅读:
    hdu 5045 Contest
    hdu 4068 SanguoSHA
    TSP 旅行商问题(状态压缩dp)
    haoi2015 树上操作
    noi 2015 软件包管理器(树链剖分)
    zjoi2008 树链剖分
    读入优化
    动态规划类型总结
    有关Rujia Liu 动态规划的·一些总结
    输入优化
  • 原文地址:https://www.cnblogs.com/fly-book/p/11340428.html
Copyright © 2011-2022 走看看