(1)byte(字節(jié)型) 1字節(jié)
short(短整型) 2字節(jié)
int(整型) 4字節(jié)
long(長(zhǎng)整型)8字節(jié)
float(單精度)4字節(jié)
double (雙精度)8字節(jié)
char (字符型) 1字節(jié)
bolean (布爾型) 1 or 4字節(jié)
(2)% 取余數(shù)
public class ASD{ public static void main(String[] args) { int i =5; int o =2; System.out.println(i%o);} }
3)string 類 首字母大寫
4)一對(duì)小括號(hào)代表一個(gè)方法
5)length 字符串長(zhǎng)度
String str = "asdfads"; int charLen = str.length(); System.out.println(charLen);
6)compareTo 比較 結(jié)果int型
7)等號(hào) == 雙等號(hào) if 如果if只有一條語句{ } 可以去掉
public class ASD{ public static void main(String[] args) { String str1 = "Google"; String str2 = "google"; int result = str1.compareTo(str2); if (result == 0) { System.out.println("111"); }else { System.out.println("22222"); } System.out.println(result);} }
8)compareToIgnoreCase 忽略大小寫
public class ASD{ public static void main(String[] args) { String str1 = "foogle"; String str2 = "google"; int result = str1.compareTo(str2); System.out.println(result); } }
9)equals 等于 結(jié)果只有 等于 不等于
public class ASD{ public static void main(String[] args) { String str1 = "Google"; String str2 = "google"; if (str1.equals(str2)); System.out.println("str1=str2"); } }
10)indexOf 尋找后面的字符在字符串第一次出現(xiàn)的位置 沒找到返回-1
空格也算一個(gè)位置 (" ",5) 從第5個(gè)位置開始找
public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; int index1=str1.indexOf("o",5); System.out.println(index1);} }
11)startsWith 前綴
public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; boolean isStare = str1.startsWith("G"); System.out.println(isStare);} }
12)endsWith 后綴
public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; boolean endWith = str1.endsWith("G"); System.out.println(endWith);}}