public List<String> getRecommendenResult(List<String> picAndVideo,int maxInterval){ List<String> result=new ArrayList<>(); if(picAndVideo==null || picAndVideo.size()==0){ return result; } Queue<String> videoQueue=new LinkedList<>(); Queue<String> picQueue=new LinkedList<>(); boolean firstPic=false; int index=0; int pciAndVideoSize=picAndVideo.size(); while(!firstPic&&index<picAndVideo.size()){ if(isVideo(picAndVideo.get(index))){ result.add(index,pciAndVideo.get(index)); }else{ first=true; } } while(index<picAndVideoSize){ if(isVideo(picAndVideo.get(index))){ videoQueue.add(index,picAndVideo.get(index)); }else{ picQueue.add(index,picAndVideo.get(index)); } } int currentSize=result.size(); while(!videoQueue.isEmpty()&&!picQueue.isEmpty()){ if(currentSize>=maxInterval){ result.add(picQueue.poll()); currentSize=0; }else{ result.add(videoQueue.poll()); currentSize++; } } while(!videoQueue.isEmpty()){ result.add(videoQueue.poll()); } if(currentSize>=maxInteral&&!picQueue.isEmpty()){ result.add(pic.poll()); } return result; } public boolean isVideo(String clip){ if(clip.indexOf("v")!=-1){ return true; } return false; }