java 2 10_10.2java

1.“==”与equals的区别

== 是引用是否相等,equals是内容相等

Integer a = new Integer(1);

Integer b = new Integer(1);

if (a = b)...         //错误

if(a.equals(b))...       //正确

public class TestEqualsString {

public static void main(String[] args) {

String name1 = new String("LiMing");

String name2 = new String("LiMing");

System.out.println( name1==name2 );                            //两个对象的引用,不相等

System.out.println( name1.equals(name2) );                  // 内容,相等

String name3 = "LiMing";

String name4 = "LiMing";

System.out.println( name3==name4 );                               //相同常量的引用,相等

System.out.println( name3.equals(name4) );                     // 内容,相等

}

}

2.getClass()

getClass()方法是final方法,不能被重载

3.toString()

用来返回对象的字符串表示,常用来显示  System.out.println(person);,也可以用于字符串的加号

4.包装类的特点

*提供常数,如Integer.MAX_VALUE等

*提供了valueOf(String),toString(),用于从字符串转换或换成字符串

*toString(),equais()等方法进行覆盖

5.包装与拆包

Integer I = 10; 即I = Integer.value(10);

int i I;即i= I.intValue();

6.System类

在命令运行Java程序时可使用 -D 选项添加新的系统属性

import java.util.*;

class SystemProperties

{

public static void main(String[] args)

{

Properties props = System.getProperties();

Enumeration keys = props.propertyNames();

while(keys.hasMoreElements() ){

String key = (String) keys.nextElement();

System.out.println( key + " = " + props.getProperty(key) );

}

}

}

7.字符串

第一类:String类,创建后不再做修改和变动

第二类:StringBuffer,StringBuilder类,创建后允许更改和变动

import java.util.*;

class StringAndStringBuffer

{

public static void main(String[] args)

{

String a = "a";

String s = "";

StringBuffer sb = new StringBuffer();

final int N = 10000;

long t0 = System.currentTimeMillis();

for( int i=0; i

long t1 = System.currentTimeMillis();

for( int i=0; i

long t2 = System.currentTimeMillis();

System.out.println(t1-t0);

System.out.println(t2-t1);

}

}

8.Math类

做一些常用的数字计算

public class TestMath{

public static void main (String args[])

{

System.out.println("Math.ceil(3.1415)=" + Math.ceil(3.1415));

System.out.println("Math.floor(3.1415)=" + Math.floor(3.1415));

System.out.println("Math.round(987.654)=" + Math.round(987.654));

System.out.println("Math.max(-987.654,301)=" + Math.max(-987.654,301));

System.out.println("Math.min(-987.654,301)=" + Math.min(-987.654,301));

System.out.println("Math.sqrt(-4.01)=" + new Double(Math.sqrt(-4.01)).isNaN());

System.out.println("Math.PI=" + Math.PI);

System.out.println("Math.E=" + Math.E);

}

}

9.StringBuffer类

构造方法:

StringBuffer()

StringBuffer(int cap)

StringBuffer(String intitial)

10.字符串的分割

java.util.StringTokenizer类提供对字符串进行分割的功能

构造:StringTokenizer(String str,String delim);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值