赞
踩
package com.wonders.week01; /** * 以JDK1.7为基础 * java.lang.Character类 * (1)是final修饰的类 * (2)实现了接口java.io.Serializable, Comparable<Character> * (3)该类具有内部类:public static class Subset * (a)成员变量private String name * (b)方法: * protected Subset(String name) 如果name为null,会抛出NullPointException * public final boolean equals(Object obj) * public final int hashCode() * public final String toString() * 内部类:public static final class UnicodeBlock extends Subset * 内部类:private static class CharacterCache * (4)构造方法: * public Character(char value) * @author liyongyong * */ public class CharacterTest { static Character character = (Character)'a'; public static void main(String[] args) { System.out.println(Character.MIN_RADIX);//2 System.out.println(Character.MAX_RADIX);//36 System.out.println(Character.MIN_VALUE);//'\u0000' System.out.println(Character.MAX_VALUE);//'\uFFFF' /* * public static Character valueOf(char c) * (1)静态方法,返回值类型Character对象 * (2)参数类型是char,字符型 */ Character c1 = Character.valueOf('1'); System.out.println(c1);//1 Character c2 = Character.valueOf('@'); System.out.println(c2);//@ /* * public char charValue() * (1)非静态方法,返回值类型char,无参数 * (2)如果Character对象为null,调用charValue方法会报NullPointException异常 */ char ch1 = character.charValue(); System.out.println(ch1);//a /* * public int hashCode() * (1)非静态方法,无参数,返回值类型是int类型 * (2)返回值是将值强制类型转为int型返回 */ int chHashCode = character.hashCode(); System.out.println(chHashCode);//字符a的哈希值是97 /* * public boolean equals(Object obj) * (1)非静态方法,返回值类型是boolean型,参数是一个对象 * (2)如果该对象是Character的对象,将对象强转为Character型并且调用charValue()方法 * 根据判断结果返回true或者false * (3)如果对象不是Character的对象,直接返回false */ boolean flag = character.equals((Character)'a'); System.out.println(flag);//true boolean flag1 = character.equals((Character)'b'); System.out.println(flag1);//false boolean flag2 = character.equals(3); System.out.println(flag2);//false /* * public String toString() * (1)非静态方法,无参数,返回值类型是String类型 * (2)调用了String.valueOf()方法 */ String str1 = character.toString(); System.out.println(str1);//a /* * public static String toString(char c) * (1)静态方法,返回值类型是String类型,参数是一个字符型char * (2)调用了String.valueOf(char c)方法 */ String str2 = Character.toString('$'); System.out.println(str2);//$ /* * public static boolean isLowerCase(char ch) * (1)静态方法,返回值类型是布尔型,参数是一个字符char */ boolean flag3 = Character.isLowerCase('A'); System.out.println(flag3);//false /* * public static boolean isLowerCase(int codePoint) * (1)静态方法,返回值类型是boolean,参数是一个int型 */ boolean flag4 = Character.isLowerCase(2); System.out.println(flag4);//false /* * public static boolean isUpperCase(char ch) * (1)静态方法,返回值类型是布尔型,参数是一个字符char */ boolean flag5 = Character.isUpperCase('A'); System.out.println(flag5);//true /* * public static boolean isUpperCase(int codePoint) * (1)静态方法,返回值类型是boolean,参数是一个int型 */ boolean flag6 = Character.isUpperCase(2); System.out.println(flag6);//false /* * public static boolean isDigit(char ch) * (1)静态方法,返回值类型是布尔型,参数是一个字符char */ boolean flag7 = Character.isDigit('2'); System.out.println(flag7);//true /* * public static boolean isDigit(int codePoint) * (1)静态方法,返回值类型是boolean,参数是一个int型 */ boolean flag8 = Character.isDigit(2); System.out.println(flag8);//false } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。