zoukankan      html  css  js  c++  java
  • '大'、'小'前后比较并归类

    '大'、'小'前后比较并归类,两种处理方式(1.前台;2.后台):

    1.在前台处理:

    <script type="text/javascript"> 
    /*大、小前后比较并归类 start*/
    var openNum1 = [
            {
                openNum1 : "小"
            },
            {
                openNum1 : "大"
            },
            {
                openNum1 : "小"
            },
            {
                openNum1 : "大"
            },
            {
                openNum1 : "小"
            },
            {
                openNum1 : "小"
            },
            {
                openNum1 : "小"
            }
    ]
    var newArr = [];
    var arr = [];
    for(var i=0;i<openNum1.length;i++){
        debugger;
        if(i+1 == openNum1.length){
            arr.push(openNum1[i]);
            newArr.push(arr);
            break;
        }
        if(openNum1[i].openNum1 == openNum1[i+1].openNum1){
            arr.push(openNum1[i]);
        }else{
            arr.push(openNum1[i]);
            newArr.push(arr);
            //清空数组
            arr = new Array();
        }
        
    }
    /*大、小前后比较并归类 end*/
    debugger;
    </script>

    结果:

    2.在后台处理:

    package test;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.test.www.entity.OpenNum1;
    /**
     * 归类
     * @className GuiLei
     * @author liuyachao
     * @date 2018-1-12
     */
    public class GuiLei {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            /**
             * 大、小前后比较并归类
             */
            guilei();
        }
        
        public static void guilei(){
            List<OpenNum1> openNum1 = new ArrayList<OpenNum1>();
            OpenNum1 p1 = new OpenNum1();
            p1.setOpenNum1("小");
            OpenNum1 p2 = new OpenNum1();
            p2.setOpenNum1("大");
            OpenNum1 p3 = new OpenNum1();
            p3.setOpenNum1("小");
            OpenNum1 p4 = new OpenNum1();
            p4.setOpenNum1("大");
            OpenNum1 p5 = new OpenNum1();
            p5.setOpenNum1("小");
            OpenNum1 p6 = new OpenNum1();
            p6.setOpenNum1("小");
            OpenNum1 p7 = new OpenNum1();
            p7.setOpenNum1("小");
            openNum1.add(p1);
            openNum1.add(p2);
            openNum1.add(p3);
            openNum1.add(p4);
            openNum1.add(p5);
            openNum1.add(p6);
            openNum1.add(p7);
            
            //新的list集合
            List newArr = new ArrayList(); 
            //临时的list集合
            List arr = new ArrayList(); 
            for(int i = 0;i<openNum1.size();i++){
                if(i+1 == openNum1.size()){
                    arr.add(openNum1.get(i));
                    newArr.add(arr);
                    break;
                }
                if(openNum1.get(i).getOpenNum1() == openNum1.get(i+1).getOpenNum1()){
                    arr.add(openNum1.get(i));
                }else{
                    arr.add(openNum1.get(i));
                    newArr.add(arr);
                    //清空数组
                    arr = new ArrayList();
                }
            }
            System.out.println(newArr);
            /* 结果:
             * [
                 [OpenNum1 [openNum1=小]], 
                 [OpenNum1 [openNum1=大]], 
                 [OpenNum1 [openNum1=小]], 
                 [OpenNum1 [openNum1=大]], 
                 [OpenNum1 [openNum1=小], OpenNum1 [openNum1=小], OpenNum1 [openNum1=小]]
               ]
             */
        }
    }
  • 相关阅读:
    7天入门JavaScript,第一天
    linux 下 启动web项目报 java.net.UnknownHostException
    HashMap 和 Hashtable
    Servlet 两种跳转方式
    SpringMVC
    把当前时间(NSDate)转为字符串
    写入数据到Plist文件中时,第一次要创建一个空的数组,否则写入文件失败
    实现多个UIView之间切换的动画效果
    missing required architecture x86_64 in file 不支持64位
    获取IOS bundle中的文件
  • 原文地址:https://www.cnblogs.com/super-chao/p/8277051.html
Copyright © 2011-2022 走看看