java数组如何进行插入删除(很菜的问题)
来源:百度知道 编辑:UC知道 时间:2024/05/26 16:31:22
1.将1-100一次添加到ArrayList对象中,然后删除奇数。
2.对上面的对象,依次插入1-100中的技术,使其恢复到1-100。
3.利用Iterator遍历该ArrayList对象并输出遍历结果。
2.对上面的对象,依次插入1-100中的技术,使其恢复到1-100。
3.利用Iterator遍历该ArrayList对象并输出遍历结果。
java数组插入实现思路:
可以把某个整数插入到整型数组的特定位置,数组中原有元素向后移动
删除方法:能够从整形数组中特定位置删除掉一个元素,数组中原有元素向前移动
程序代码:
InsertDelete.java:
package p1;
import com.kettas.common.*;
import java.util.*;
public class InsertDelete
{
static int[] a={4,2,7,3,5};//初始数组
static int sum=5;//数组的有效位数
public static void main(String[] args)
{
System.out.println("初始数组为:");
output();
while(true)
{
System.out.println("操作:1:插入;2:删除;3:退出");
int option=SystemIn.readInt();
if(option==1)
{
System.out.println("请输入插入的位置:");
int pos=SystemIn.readInt();