在LinkedList中迭代和搜索

时间:2018-04-07 05:42:07

标签: java linked-list singly-linked-list

我正在打印LinkedList,如下所示:

    public class cinema{

    public static LinkedList <cinema> cinList = new LinkedList<cinema>();
    private int cinemaNum,numSeats;
    private String row;

    public cinema(int getCinemaNumber,String getRowName,int getNumSeats){
        this.cinemaNum = getCinemaNumber;
        this.row = getRowName;
        this.numSeats = getNumSeats;
        //todo
    }




    public static void addHalls(cinemaValues cin){
        cinema Cinema = new cinema(cin.getCinemaNumber(), cin.getRowName(),cin.getNumSeats());
        cinList.add(Cinema);
    }

    public static void print(){
        System.out.println(cinList);
    }

    @Override
    public String toString() {
        return "cinnum:"+cinemaNum+" row:"+row+" seats:"+numSeats;
    }

}    

public class session{

            public static LinkedList <session> sessList = new LinkedList<session>();
            private int CinemaSessionNum;
            private String time,movie;

            public session(int getCinemaSessionNum, String getTime,String getMovie){
                this.CinemaSessionNum = getCinemaSessionNum;
                this.time = getTime;
                this.movie = getMovie;
            }

            public static void addSession(CinemaSessions sess){
                session ses = new session(sess.getCinemaSessionNum(),sess.getTime(),sess.getMovie());
                sessList.add(ses);
            }
            public static void print(){
                System.out.println(sessList);
            }

            @Override
            public String toString() {
                return "cinnum:"+CinemaSessionNum+" time:"+time+" movie:"+movie;
            }
        }

输出:

enter image description here

我想要一种能够使用其中一个键

搜索元素的所有三个部分的方法

基本上, 当条件是Cinnum:2我希望它返回 Cinnum:1次:9:00电影:玩具 Cinnum:1次:14:30电影:料理鼠王

任何帮助都将不胜感激。

由于

0 个答案:

没有答案