码迷,mamicode.com
首页 > 编程语言 > 详细

java list 连续n个点大于某个值

时间:2017-09-08 11:38:04      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:nbsp   out   ack   util   port   integer   sys   sub   string   

package com.pr.cms.controller;

import java.util.ArrayList;
import java.util.List;

public class test {


    public static void main(String[] args){

        List<Integer> list = new ArrayList<>();
        list.add(7);
        list.add(8);
        list.add(19);
        list.add(20);
        list.add(21);
        list.add(-21);
        list.add(25);


        int  m = 0;
        int i = 0;

        //连续在同一侧
        List<Integer> subList = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            Integer tmpv = list.get(j);
            if (tmpv > m) {
                if (subList != null&& subList.size() > 0) {
                    Integer integer = subList.get(subList.size() - 1);
                    if (tmpv -integer > 0) {
                        subList.add(tmpv);
                        i+=1;
                    }else{
                        subList.remove(0);
                        subList.add(tmpv);
                    }
                }else{
                    i+=1;
                    subList.add(tmpv);
                }
            }else{
                i = 0;
                subList.clear();
            }
            if (i == 3) {
                System.out.println(subList.toString());
                subList.clear();
                i = 0;
            }

        }
    }

}

java list 连续n个点大于某个值

标签:nbsp   out   ack   util   port   integer   sys   sub   string   

原文地址:http://www.cnblogs.com/yaoyao66123/p/7493245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!