zoukankan      html  css  js  c++  java
  • 6、字符串生成器 String-Builder

    package com.xxx.xxx;
    
    public class demo7 {
    
        /**
         * 字符串生成器    
         * J2SE 可变的字符串序列    String-Builder类
         * @param args
         */
        public static void main(String[] args) {
            String str = "";    //创建空字符串
            //定义对字符串执行操作的起始时间
            long startTime = System.currentTimeMillis();
            for(int i = 0; i < 1000; i++){    //利用 for 循环执行1000次
                str = str + i;    //循环追加字符串
            }
            long endTime = System.currentTimeMillis();    //定义对字符串操作后的时间
            long time = endTime - startTime;        //计算对字符串执行的时间
            System.out.println("Str 消耗时间:"+time);
            //创建字符串
            StringBuilder builder = new StringBuilder("");
            startTime = System.currentTimeMillis();    //定义操作执行前的时间
            for(int j = 0; j < 100000 ; j++ ){
                builder.append(j);        //循环追加字符串
                //System.out.println(builder.append(j));
            }
            endTime = System.currentTimeMillis();
            time = endTime - startTime;
            System.out.println("StringBuilder 消耗时间:"+time);
            
            
        }
    
    }
  • 相关阅读:
    C++实现base64编解码
    使用matplotlib绘制3D函数图像
    C++分治策略实现快速排序
    C++分治策略实现二分搜索
    C++生成随机数
    eBay 表结构
    mysql 流程函数
    无限极分类
    PHP 导出 Excell
    js
  • 原文地址:https://www.cnblogs.com/spadd/p/4164494.html
Copyright © 2011-2022 走看看