数组定义
数据类型 名称[] = new 数据类型[n]
int data[] = new int[3];data[0] = 10;data[1] = 11;data[2] = 25;
一步定义数组,并循环输出
int data[] = new int[] {1,2,3,4};for (int i : data) {System.out.println(i);}
字符串数组定义,并循环
String data[] = new String[] {"sss","kejin","laowan"};for (String i : data) {System.out.println(i);
str.substring(4);
切割前四个字符,保留后面的
str.substring(4,5);
切割前四个字符,切割后四个字符保留剩下的
map的使用(存放键值对)
Map m1 = new HashMap<K, V>();m1.put("name","aaa");m1.put(2,"bbb");System.out.println(m1.get("name"));System.out.println(m1.size());
动态数组
public class array1 {
public static void main(String[] args) {int[] a=new int[11];for (int i = 0; i < 11; i++) {a[i]=i*5;}a[10]=100;System.out.println("**************");for (int m:a) {System.out.println(m);}
}
}二维数组```c
public class array2 {
public static void main(String[] args) {int[][] a=new int[4][4];a[3][3]=100;for (int j = 0; j <= 3; j++) {for (int k = 0; k<=3; k++) {a[j][k]=1;}}a[3][3]=100;for (int i = 0; i <=3; i++) {for (int m = 0; m <=3; m++) {System.out.print( a[i][m] +"\t" );}System.out.println(" ");}
} }