ASP.Net+Android+IOS开发------期待与您交流
<String类总结>
<02-字符串缓冲区 & 其他常用对象>
1. StringBuffer字符串缓冲区
* append()向缓冲区追加数据,返回值还是StringBuffer
* 方法的调用链
* insert()指定位置插入数据
* setCharAt(int index ,char ch)修改指定位置上的字符
* reverse()反转缓冲区内的字符
* delete(start,end)删除缓冲区中的字符
2. StringBuilder 也是字符串缓冲区
* StringBuffer 和 StringBuilder(JDK1.5)中的方法一摸一样
* 区别在哪里
* StringBuffer 是线程安全的 效率低
* StringBuilder 是线程不安全的 效率高,推荐使用
* JDK版本1.5含以上
* 开发的程序是单线程的,推荐Builder
* 开发一个多线程的程序,推荐Buffer
字符串缓冲区的各种方法代码演示如下:
public class StringBufferDemo {
public static void main(String[] args) {
method_2();
StringBuffer sb1 = new StringBuffer("kl");// kl
StringBuffer sb2 = new StringBuffer();//
sb2.append("ss");//sb ss
test(sb1, sb2);
System.out.println(sb1);
System.out.println(sb2);
}
private static void test(StringBuffer sb1,StringBuffer sb2){
sb1.append(sb2);//sb1=kl sb2=ss sb1=klss
sb1.append(sb1);//klssklss
}
/*
* 删除缓冲区内的字符
* delete(开始下标,结束下标)包含头,不包含尾
* deleteCharAt
*/
private static void method_3(){
StringBuffer sb = new StringBuffer();
sb.append("abcdef");
sb.deleteCharAt(2);
sb.delete(0, sb.length());
System.out.println(sb);
}
/*
* 反转缓冲区内的字符
* void reverse()
*/
private static void method_2(){
StringBuffer sb = new StringBuffer();
sb.append("a24235");
sb.reverse();
System.out.println(sb);
}
/*
* 修改指定索引上的字符
* void setCharAt(int index, char ch)
*/
private static void method_1(){
StringBuffer sb = new StringBuffer();
sb.append("abcdef");
System.out.println(sb);
sb.setCharAt(1, 'G');
System.out.println(sb);
}
/*
* StringBuffer insert
* 指定位置上,插入数据,后面的顺延
*/
private static void method(){
StringBuffer sb = new StringBuffer();
sb.append("abcdef");
System.out.println(sb);
sb.insert(0, 3.14);
System.out.println(sb);
}
}
3. System
* System类的常见方法
确定当前的系统属性。
static Properties getProperties()
* 传递是的键
static String getProperty(String key)
* 结束虚拟机
System.exit(0);
4. Runtime类
* 私有构造方法
* static Runtime getRuntime()
* 单例模式设计
* exec(可以行文件 被打开的文件)
* 返回进程对象Process
* 进程对象中 destory()杀掉子进程,只能杀掉exec开启的进程
5. Math类,数学方面的计算,此类中方法,全部是static
* Math.E
* Math.PI 圆周率
* abs()获取一个数的绝对值
* ceil()大于或者等于参数的最小整数 分页*****
* floor()小于或者等于参数的最大整数****
* round()四舍五入
* pow()幂运算
* random() *****
* 另一种随机数产生方法 Random类
*Random r = new Random();
* nextInt(范围) 推荐*****
6. Integer类-- 基本数据类型,对象包装类
* 将基本数据类型,包装成对象,提供方法和属性
* MAX_VALUE MIN_VALUE 静态的常量
* static int parseInt(字符串)将字符串转成int类型 *****
* int intValue() 将Integer包装的数据,转成基本数据类型
* static String toString()
* 自动装箱,自动拆箱
* byte 取值范围,不开辟新的内存空间
boolean ==> Boolean
byte ==> Byte
short ==> Short
int ==> Integer
long ==> Long
float ==> Float
double ==> Double
char ==> Character
Integer的常用方法及使用方式:
package cn.itcast.other;
/*
* JDK1.5后新特性
*/
public class IntegerDemo1 {
public static void main(String[] args) {
//Integer x = 3 ; Integer x = new Integer(3); 自动装箱
Integer x = 3;
x = x + 3;//x=x+3 x=x.intValue()+3 自动拆箱 x=new Integer(6) 自动装箱
System.out.println(x);
Integer y = null;
if(y!=null){
y = y + 3;//null.intValue()
System.out.println(y);
}
Integer a = new Integer(4);
Integer b = new Integer(4);
System.out.println(a==b);//false
System.out.println(a.equals(b));//true
System.out.println("--------------------------------");
Integer aa = 345;//new Integer(345);
Integer bb = 345;//new Integer(345);
System.out.println(aa==bb);//false
System.out.println(aa.equals(bb));//true
System.out.println("===========================");
Integer aaa = 127;
Integer bbb = 127;
System.out.println(aaa==bbb);//true
System.out.println(aaa.equals(bbb));//true
/*
* 原因是,取值范围是byte的时候,JVM不在开辟新的内存空间 aaa bbb指向同一堆内存
*/
}
}
7. 描述日期对象的类,Date util包
* 构造 Date() Date(毫秒)
* getTime()
* setTime()
8. 将日期进行格式化
* SimpleDateFormat
* 将日期格式化成什么形式,这个类的构造方法来定义
* String format(日期对象)
9. 两个日期之间相差多少天
* 日期 ,由用户在控制台输入
* 结果就是相差的天数
* DateFormat df = DateFormat.getDateInstance();
df.parse(String)转成日期对象
日期对象转成毫秒值
毫秒值相减
10. Calendar 日历类
* static getInstance() 返回日历对象
* get()获取日历中的部分
* set()设置日期
* add()指定的字段,进行偏移
11. Timer类 定时器
* public void schedule(TimerTask task,
Date firstTime,
long period)
ASP.Net+Android+IOS开发------期待与您交流