⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newlistuse.java

📁 本java源程序包括了大量的学习程序(共27章)方便大家学习
💻 JAVA
字号:
import java.util.*;
public class NewListUse 
{
	//创建新的List集合类型对象list
	NewList<Double> list=new NewList<Double>();

	public NewListUse()
	{
		//向list对象中添加数据元素
		list.add(100.00);
		list.add(2.4);
		list.add(10.30);
		list.add(100.00/3);
		
		//显示添加到list中的元素
		System.out.println("The elements of list are:");
		double d1[] = new double[4];
		for (int i = 0; i < d1.length; i++) 
		{
			d1[i] = list.get(i);
			System.out.println(d1[i]);
		}
		
		//修改list对象中元素并显示
		System.out.println("\nAfter modified ,the elements of list are:");
		//修改指定位置上元素的值
		list.set(0,999.999);
		list.set(1,0.24);
		//显示list中数据
		double d2[] = new double[4];
		for (int i = 0; i < d2.length; i++) 
		{
			d2[i] = list.get(i);
			System.out.println(d2[i]);
		}
		
		//删除list对象中元素并显示
		System.out.println("\nAfter removed ,the elements of list are:");
		//删除list对象中,指定位置上的元素
		list.remove(0);
		//显示list中数据
		double d3[] = new double[3];
		for (int i = 0; i < d3.length; i++) 
		{
			d3[i] = list.get(i);
			System.out.println(d3[i]);
		}			
	}
	
	public static void main(String[] args) 
	{
		new NewListUse();
	}
}

class NewList<Double>
{
	//创建新的List序列集合类型对象list,使其存储内容都Double类型数据
	public List<Double> list = new LinkedList<Double>();
	
	//方法过载:向LinkedList中添加数据
	public void add(Double d)
	{
		list.add(d);
	}
	
	//方法过载:获取LinkedList中index指定位置的数据
	public Double get(int index)
	{
		return list.get(index);
	}
	
	//方法过载:获取Iterator对象
	public Iterator<Double> iterator()
	{
		return list.iterator();
	}
	
	//方法过载:移除LinkedList中index指定位置的数据
	public Double remove(int index)
	{
		return list.remove(index);
	}
	
	//方法过载:设置LinkedList中index指定位置的数据
	public Double set(int index,Double d)
	{
		return list.set(index,d);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -