一、数组
1.声明数组
数据类型 数组名[]; 如:String stuName[];
数据类型[] 数组名; 如:String[] stuName;
2.分配空间
数据类型[] 数据名 = new 数据类型[数组长度]; 如: int score = new score[30];
3.赋值
数组名[下标值] 如:score[0] = 89;
数据类型[] 数据名 = {值1,值2,值3,......}; 如:int[] score = {89,96,63,86};
数据类型[] 数据名 = new 数据类型[]{值1,值2,值3,.....}; 如:int[] score = new int[]{2,3.5,6};
4.数组长度 数组名.length;
5.数组范围 0 到 (数组长度-1)
6. binarySearch() 对数组进行二次检索
Arrays.sort(数组名);对数组进行升序排(小-->大) 需要导入 java.util.Arrays包
7. 数组元素出数值
int 0
double 0.0
char ‘\u0000’
boolean false
8.应用
1 //求最大值 2 int[] score = new int[5]; 3 int max = score[0]; 4 for(int index =0; index <5 ; index++){ 5 if(score[index] > max){ 6 max = score[index]; 7 } 8 } 9 System.out.println("最大数为:"+max);
二、字符串
String.length(); 长度
"字符串1".equals("字符串2") 比较字符串是否相等
字符串.equalsIgnoreCase(字符串2) 忽略大小写
字符串.toLowerCase() 转换字符串中英文字母为小写
字符串.toUpperCase() 转换字符串中英文字母为大写
+ 或 concat() 连接字符串
indexOf(int ch) 搜索第一个出现字符ch(或字符串value) 如果没有匹配的返回-1
lastIndexOf(int ch) 搜索最后一个出现字符ch(或字符串value)
substring(int index) 从位置索引开始的字符串部分
substring(int beginIndex,int endIndex) 提取beginIndex和endIndex之间的字符串部分
trim() 返回一个前后不含空格的调用字符串的副本。
计算起始位置: 0 1 2 3 4 5
今天心情很好
计算终止位置: 1 2 3 4 5 6
String 比 StringBuffer 效率低
String 操作副本
StringBuffer操作字符串本身
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号