• StringBuffer工具类整理(一)


     1 package com.gzcivil.utils;
     2 
     3 /**
     4  * 同StringBuffer
     5  * 
     6  * @author Dragon
     7  * @time 2013-3-1
     8  */
     9 public class StrBuffer {
    10     private StringBuffer sb = null;
    11 
    12     public StrBuffer() {
    13         sb = new StringBuffer();
    14     }
    15 
    16     public StrBuffer(Object... objects) {
    17         sb = new StringBuffer();
    18         append(objects);
    19     }
    20 
    21     public StringBuffer append(Object... objects) {
    22         if (objects != null) {
    23             for (Object o : objects) {
    24                 sb.append(o);
    25             }
    26         }
    27         return sb;
    28     }
    29 
    30     public int length() {
    31         return sb.length();
    32     }
    33 
    34     public int indexOf(String string) {
    35         // TODO Auto-generated method stub
    36         return sb.indexOf(string);
    37     }
    38 
    39     public int lastIndexOf(String string) {
    40         return sb.lastIndexOf(string);
    41     }
    42 
    43     public int indexOf(String subString, int start) {
    44         // TODO Auto-generated method stub
    45         return sb.indexOf(subString, start);
    46     }
    47 
    48     public String substring(int start, int end) {
    49         // TODO Auto-generated method stub
    50         return sb.substring(start, end);
    51     }
    52 
    53     public String toString() {
    54         return sb.toString();
    55     }
    56 
    57     public char charAt(int index) {
    58         return sb.charAt(index);
    59     }
    60 
    61     public boolean equals(Object obj) {
    62         if (this == obj)
    63             return true;
    64 
    65         if (obj != null && obj.getClass() == this.getClass()) {
    66             StrBuffer sb = (StrBuffer) obj;
    67             int len = length();
    68             if (len != sb.length())
    69                 return false;
    70             int index = 0;
    71             while (index != len) {
    72                 if (charAt(index) != sb.charAt(index))
    73                     return false;
    74                 else
    75                     index++;
    76             }
    77             return true;
    78         }
    79         return false;
    80     }
    81 }
  • 相关阅读:
    C语言I—2019秋作业02
    C语言I—2019秋作业01
    C语言I博客作业01
    C语言I博客作业09
    C语言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
  • 原文地址:https://www.cnblogs.com/lijinlun0825/p/5174804.html
Copyright © 2020-2023  润新知