赞
踩
Scanner sc = new Scanner(System.in);
//开启键盘录入
String s = sc.next();
String s = sc.nextLine();
方法 | 说明 |
---|---|
public String() | 创建一个空白字符串,其中不含任何内容 |
public String(char[] chs) | 据字符数组内容创建字符串 |
public String(String original) | 据传入的字符串,传入字符串对象 |
String s = “abc” | 以直接赋值方式创建字符串对象,赋值为abc |
public boolean equals(Object object) | 比较字符串内容,严格区分大小写 |
public boolean equalsIgnoreCase(String anotherString) | 比较字符串内容,忽略大小写 |
public int length() | 返回字符串长度 |
public char charAt(int index) | 返回指定索引处的char值 |
public char[] toCharArray() | 将字符串拆分为字符数组后返回 |
public String subString(int beginIndex,int endIndex) | 根据开始和结束索引进行截取,得到新的字符串(包含头,不包含尾) |
public String subString(int beginIndex) | 从传入的索引处截取,截取到末尾,得到新的字符串 |
public String replace(CharSequence target,CharSequence replacement) | 使用新值,将字符串中旧的替换,得到新的字符串 |
public String[] split(String regex) | 据传入规则切割字符串,得到字符串数组 |
" "
方式给出字符串,只要字符序列相同,无论程序中出现多少次,JVM都只建立一个String对象,并在字符串池中维护public boolean equals(String s)
,比较两个字符串内容是否相同、区分大小写
String s1 = "abc";
String s2 = "abc";
System.out.println(s1.equals(s2);
//例
String[] sArr = str.split(",") //据字符串中逗号分割字符串
方法 | 说明 |
---|---|
public StringBuilder() | 创建空白可变字符串对象,不含任何内容 |
public StringBuilder(String str) | 据字符串内容创建可变字符串对象 |
public StringBuilder append(任意类型) | 添加数据并返回对象本身 |
public StringBuilder reverse() | 返回相反的字符序列 |
public String toString()
:通过toString把StringBuilder转为Stringpublic StringBuilder(String s)
:通过构造方法实现String转为StringBuilder方法名 | 说明 |
---|---|
static double abs(double a) | 返回double值的绝对值 |
static double ceil(double a) | 返回最小的(最接近负无穷大)的double值,该值大于或等于参数,且等于某个整数 |
static double floor(double a) | 返回最大的(最接近正无穷大)的double值,该值小于或等于参数,且等于某个整数 |
static double max(double a,double b) | 返回两个double值中较大的一个 |
static double min(double a,double b) | 返回两个double值中较小的一个 |
static double pow(double a,double b) | 返回第一个参数的第二个参数次幂值 |
static double random() | 返回带正号的double值,大于等于0.0,小于1.0 |
static int round(float a) | 返回最接近参数的int,四舍五入取整 |
static double sqrt(double a) | 返回正确舍入的double值的正平方根 |
//例
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
java.util.Date();
,创建一个代表当前时间的日期对象Date()
:Date(long date)
:据toString()
:直接返回当前时间getTime()
:返回自1970年至今的毫秒数
setTime()
:设置时间,给的是毫秒值getInstance()
方法或通过Calendar子类GregorianCalendar获取实例方法名 | 说明 |
---|---|
public int get(int field) | 返回给定日历字段的值 |
public void set(int field,int value) | 将给定的日历字段设定为给定值 |
public abstract void add(int field,int amount) | 据日历规则,为给定日历字段添加或减去指定时间量 |
public Date getTime() | 返回一个表示此Calendar时间值(从历元到毫秒偏移量)的Date对象 |
字段值 | 含义 |
---|---|
YEAR | 年 |
MONTH | 月 |
DAY_OF_MONTH | 月(从0开始,故一般使用需+1) |
HOUR | 时(12小时制) |
HOUR_OF_DAY | 时(24小时制) |
MINUTE | 分 |
SECOND | 秒 |
DAY_OF_WEEK | 周中的天(周几,周日为1,故一般使用需-1) |
public static final DateFormat getDateInstance(int style,Locale alocale)
public static final DateFormat getDateTimeInstance(int dateStyle,int timeStyle,Locale alocale)
public Date parse(String source) throws ParseException
public SimpleDateFormat(String pattern)
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTime( new java.util.Date());
Calendar calendar = Calendar getInstance();
calendar.set(1949,10,1,15,01);
java.util.Date date = calendar.getTime();
基本数据类型 | 包装类 |
---|---|
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Character |
boolean | Boolean |
方法 | 说明 |
---|---|
public Integer(int value) | 据int值创建Integer对象 |
public Integer(String s) | 据String值创建Integer对象 |
public static Integer valueOf(int i) | 返回指定的int值的Integer实例 |
public static Integer valueOf(String s) | 返回一个保存指定值的Integer对象String |
Integer i = 1; //自动装箱
i += 2; //自动拆箱
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。