package com.ibm.four;
public class Test {
public static void main(String[] args) {
Integer i=123;
byte b1=i.byteva lue();
System.out.println(b1);
double d1=i.doubleva lue();
System.out.println(d1);
float f1 = i.floatValue();
int i1 = i.intValue();
long l1=i.longValue();
short s1=i.shortValue();
String str1 = i.toString();
int ii = 15;
int ii1=Integer.bitCount(ii);
System.out.println(ii1);
int ii2 = Integer.parseInt(str1,8);
System.out.println(ii2);
String str2 = Integer.toBinaryString(ii);
System.out.println(str2);
String str3 = Integer.toHexString(ii);
System.out.println(str3);
String str4 = Integer.toString(ii);
System.out.println(str4);
Integer iii = Integer.valueOf(ii);
System.out.println(iii);
}
}
String类:
一些使用方法:
package com.ibm.strings;
import java.io.UnsupportedEncodingException;
public class StringDemo {
public static void main(String[] args) throws UnsupportedEncodingException {
String str = "welcome softomm ";
// 构造新的字符串的方法;
//1. concat 方法在str后面加上!
String newStr = str.concat("!");
System.out.println(newStr);
//2. replace 将字符串中的char型值替换成新的String字符串
String newStr2 = str.replace('e', 'E');
System.out.println(newStr2);
CharSequence cs = str.subSequence(0, str.length());
CharSequence cs2 = str.subSequence(0, str.length()/2);
String newStr3 = str.replace(cs2, cs);
System.out.println(newStr3);
//3. subString字符串截取
//用于截取从指定索引处到此字符串完的一个新的字符串
String newStr4 = str.substring(8);
System.out.println(newStr4);
//如果将str字符串截取成come soft
String newStr5 = str.substring(3,12);
System.out.println(newStr5);
//4. toUpperCase 将字符串按照
系统的环境转换成大写
String newStr6 = str.toUpperCase();
System.out.println(newStr6);
//5. toLowerCase将字符串转换成小写
String newStr7 = str.toLowerCase();
System.out.println(newStr7);
//6. trim去掉字符串的前后空格 如果字符串中间有空格则中间的空格不去掉
System.out.println(str.trim());
// 查找字符串的方法
String[] strs = {"a你好","a你帅","b你们","aa","bb","cc"};
//1. startWith 判断一个字符串是否以XX开始
for(String s:strs){
if(s.startsWith("a")){
System.out.println(s);
}
if(s.endsWith("帅")){
System.out.println(s+"=========");
}
}
//2. indexof lastIndexOf
//判断子字符串在某一个字符串中第一次出现的索引位置 int
int index=str.indexOf('e');
System.out.println(index);
//3.判断子字符串在某一个字符串中最后出现的索引位置 int
int last = str.lastIndexOf('e');
System.out.println(last);
//4.比较字符串的方法
//equalsIgnoreCase将此字符串与另一个字符串比较,不考虑大小写
//,只需要注意的是字符串的长度和字符串中的每一个字符的拜访顺序
boolean flag = str.equalsIgnoreCase("WelCome SofTomM");
System.out.println(flag);
//5. compareTo按字典顺序比较两个字符串。
String str8 = "a";
int j = str8.compareTo("b");
System.o