目录
一、大小写转换:
法一:函数法
法二:异或转换
package day715; /*注意: * 1、是String类下的 toLowerCase()和toUpperCase(); * 2、 */ public class 大小写转换 { public static void main(String[] args) { //法一: 函数法 String a=new String("SdaASFNvadfA/123??sdfaklKJJ"); a=a.toLowerCase(); System.out.println(a); a=a.toUpperCase(); System.out.println(a); //法二:异或转化 //char x='a'^32; /**异或 32 能实现大小写转换的核心原因是:* * ASCII 编码中,大小写字母的二进制表示仅在第 6 位不同。 * 异或 32(二进制00100000)恰好可以翻转第 6 位,从而切换大小写状态。 * */ System.out.println('a'^32); } }
二、数组
1、数组声明
一维数组:
int[] name;//首选 定义一个整数类型的数组,名字是name
int name[];//主要为了方便c、c++学员快速理解和使用
二维数组:
String[][] str =new String[3][4];
2、数组创建
int[] a=new int[8];//整数型数组a,大小为8
double[] b={1.2,2.2,3.3,4.4};
3、For-Each循环来遍历数组
for(double element:b){
System.out.println(element);
}
4、作为函数参数
//----- 定义 ------------
public static void fun(int[] array){
//具体操作
}
//------ 调用 -------------
fun(new int[]{3,2,1,24,4});
5、作为函数返回值
public static int[] reverse(int[] list){
int[] result=new int[list.length];//存储结果
//处理
//......
return result;
}
三、ArrayList数组列表
ArrayList打破普通数组需要先声明数组的规则,可以自动调整他的容量,因此,数组列表也称为动态数组。
1、创建数组:
ArrayList<Type> name=new ArrayList<>();
如:
ArrayList<Integer> name=new ArrayList<>();整数类型动态数组
ArrayList<String> name =new ArrayList<>();字符类型动态数组
还可以使用List接口创建ArrayList:
List<String> list=new ArrayList<>();
2、ArrayList的方法
(1)add(Object element)列表尾部添加指定元素
(2)size() 返回列表元素个数
(3)get(int index) 返回列表中指定位置的元素
(4)isEmpty();
(5)contains(Object o);
(6)remove(int index);