关于数组的常用方法01
2010-05-29 19:18
141 查看
package mytools.arraytool;
public class ArrayUtil {
/**
* 此个方法用于打印一个一维int类型的数组
*
* @param x
* 是要打印的int类型数组
*/
public static void oneintprint(int x[]) {
for (int y = 0; y < x.length; y++) {
System.out.print("数组[" + y + "] = " + x[y] + "/t");
}
System.out.println("");
}
/**
* 此个方法用于打印一个二维int类型的数组
*
* @param x
* 是要打印的int类型数组
*/
public static void twointprint(int a[][]) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + "/t");
}
System.out.println("");
}
}
/**
* 此个方法用于初始化一个一维int类型的数组
*
* @param len
* 代表数组的长度,你可以指定它的长度
* @return 一个int类型的数组,数组初始化为1 2 3 4 5 6 7 8 9.......
*/
public static int[] init(int len) {
// java中的数组是可以动态开辟的
int x[] = new int[len];
// 进行数组的初始化
for (int y = 0; y < x.length; y++) {
x[y] = y + 1;
}
return x;
}
/**
* 此个方法用于复制一个数组
*/
public static void copyArray() {
int[] src = { 1, 3, 10, 6, 7, 8 };
int[] dest = new int[6];
System.arraycopy(src, 0, dest, 0, 6);
ArrayUtil.oneintprint(dest);
}
/**
* 数组的声明 创建实例 可以参考
*/
public static void arraydeclare() {
int source[] = { 1, 2, 3, 4, 5, 6 };// 这是一维数组静态声明方式
int x[] = new int[10];// 这是一维数组动态声明方式
int a[][] = { { 1, 3 }, { 2, 3, 4, 5 }, { 2, 3, 4 } };//这是二维数组静态声明方式
int c[][]= new int[3][7];//这是二维数组动态声明方式
int b[][]= new int[3][];//这是二维数组动态声明方式
b[0]=new int[2];
b[0]=new int[3];
b[0]=new int[5];
// 数组的使用看的是下标
// 0 1 2 3 4 5 6 7 8 9
// 如果要打印第1个数据
System.out.println(source[0]);
}
public static void main(String args[]) {
int a[][] = { { 1, 3 }, { 2, 3, 4, 5 }, { 2, 3, 4 } };
twointprint(a);
int source[] = { 1, 2, 3, 4, 5, 6 };
oneintprint(source);
ArrayUtil.copyArray();
}
}
public class ArrayUtil {
/**
* 此个方法用于打印一个一维int类型的数组
*
* @param x
* 是要打印的int类型数组
*/
public static void oneintprint(int x[]) {
for (int y = 0; y < x.length; y++) {
System.out.print("数组[" + y + "] = " + x[y] + "/t");
}
System.out.println("");
}
/**
* 此个方法用于打印一个二维int类型的数组
*
* @param x
* 是要打印的int类型数组
*/
public static void twointprint(int a[][]) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + "/t");
}
System.out.println("");
}
}
/**
* 此个方法用于初始化一个一维int类型的数组
*
* @param len
* 代表数组的长度,你可以指定它的长度
* @return 一个int类型的数组,数组初始化为1 2 3 4 5 6 7 8 9.......
*/
public static int[] init(int len) {
// java中的数组是可以动态开辟的
int x[] = new int[len];
// 进行数组的初始化
for (int y = 0; y < x.length; y++) {
x[y] = y + 1;
}
return x;
}
/**
* 此个方法用于复制一个数组
*/
public static void copyArray() {
int[] src = { 1, 3, 10, 6, 7, 8 };
int[] dest = new int[6];
System.arraycopy(src, 0, dest, 0, 6);
ArrayUtil.oneintprint(dest);
}
/**
* 数组的声明 创建实例 可以参考
*/
public static void arraydeclare() {
int source[] = { 1, 2, 3, 4, 5, 6 };// 这是一维数组静态声明方式
int x[] = new int[10];// 这是一维数组动态声明方式
int a[][] = { { 1, 3 }, { 2, 3, 4, 5 }, { 2, 3, 4 } };//这是二维数组静态声明方式
int c[][]= new int[3][7];//这是二维数组动态声明方式
int b[][]= new int[3][];//这是二维数组动态声明方式
b[0]=new int[2];
b[0]=new int[3];
b[0]=new int[5];
// 数组的使用看的是下标
// 0 1 2 3 4 5 6 7 8 9
// 如果要打印第1个数据
System.out.println(source[0]);
}
public static void main(String args[]) {
int a[][] = { { 1, 3 }, { 2, 3, 4, 5 }, { 2, 3, 4 } };
twointprint(a);
int source[] = { 1, 2, 3, 4, 5, 6 };
oneintprint(source);
ArrayUtil.copyArray();
}
}
相关文章推荐
- Java中关于数组的常用方法
- 关于数组的一些常用方法
- 工作日常--总不能一直记流水账吧,温故下js关于数组的一些常用方法
- JAVA中关于数组初始化的常用方法
- 关于javascript数组的定义与其一些常用方法总结
- [前端] 关于数组的常用方法统计
- Objective-C中关于数组操作常用的方法
- ES6常用的数组方法
- 常用数组方法
- 数组常用的几种方法
- 关于blockKit的使用 2 UIKit文件夹下一些常用的方法
- js 数组中常用的方法
- Javascript中数组的常用方法
- 关于GCD的常用方法介绍,MRC
- JavaScript之基础-8 JavaScript 数组(创建、访问、常用方法、二维数组)
- javascript Array 数组常用方法
- Java基础学习应用_数组常用方法与排序(一)
- OC中常用的数组排序有以下几种方法
- js 数组常用的方法总结
- 常用方法一:随机数生成、检测非法字符、判断数字格式、是否为空、枚举值转化为数组