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

📄 例7-7.txt

📁 这是一本java基础教程 对新手上路有很大帮助
💻 TXT
字号:
import java.util.*; 
class Student{
    String name;
    int score;
    Student(String name,int score){
       this.name=name;
       this.score=score;
    }
}
public class Example7_7{
    public static void main(String args[]){
      LinkedList<Student> mylist=new LinkedList<Student>();
      Student stu1=new Student("张小一",78),
             stu2=new Student("王小二",98),
             stu3=new Student("李大山",67);
      mylist.add(stu1); 
      mylist.add(stu2);
      mylist.add(stu3);
      int number=mylist.size();
      System.out.println("现在链表中有"+number+"个节点: ");
      for(int i=0;i<number;i++){
         Student temp=mylist.get(i);
         System.out.printf("第"+i+"节点中的数据,学生:%s,分数:%d\n",temp.name,temp.score);
      }
      Student removeSTU=mylist.remove(1);
      System.out.printf("被删除的节点中的数据是:%s,%d\n",removeSTU.name,removeSTU.score);
      Student replaceSTU=mylist.set(1,new Student("赵钩林",68));
      System.out.printf("被替换的节点中的数据是:%s,%d\n",replaceSTU.name,replaceSTU.score);
      number=mylist.size();
      System.out.println("现在链表中有"+number+"个节点: ");
      for(int i=0;i<number;i++){
         Student temp=mylist.get(i);
         System.out.printf("第"+i+"节点中的数据,学生:%s,分数:%d\n",temp.name,temp.score);
      }
      if(mylist.contains(stu1)){
         System.out.println("链表包含"+stu1+":");
         System.out.println(stu1.name+","+stu1.score);
      }
      else{
         System.out.println("链表没有节点含有"+stu1);
      }  
    }
}

⌨️ 快捷键说明

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