List 集合中 均勻的取七個點 的值

來源:互聯網
上載者:User

標籤:

情境:

一個未知 長度的 List 集合,可能 長度為7,10,50,100, 等等

這個時候 ,我們需要在 集合中 均勻的取七個點;

思路:

    n=6;

    int size = list.Size();

    6*count = size -7-剩餘的個數;

    但是,我們怎麼知道 剩餘的個數,是多少??

    size-7 -剩餘的個數是 6的倍數,那麼,我們只要 將  (size-7)-- ,放入while迴圈裡面,直到 是6的倍數,那麼測試 ,得到的值,就是6的最大倍數了。

    

 // size = 6*num +7+剩下的數            if(size<=7){                result.put("period",period);                result.put("navSeries",navlist);                return result;            }            if((size-7)<6){                //取後7資料                for (int k=size-1;k>=0;k--){                    resplist.add((JSONObject)navlist.get(k));                }            }            if((size-7)>=6){                int numa = size-7;                int numb = numa;                while ((numb%6!=0)){                    numb--;                }                //size = 6*i+7+剩下的數                int index = numb/6;                int count=0;                for(int i=size-1;i>=0;i--){                    if(i==size-1){                        resplist.add((JSONObject)navlist.get(i));                        System.out.println(i);                        continue;                    }                    count++;                    if(count>index){                        resplist.add((JSONObject)navlist.get(i));                        System.out.println(i);                        count=0;                    }                }            }

 

List 集合中 均勻的取七個點 的值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.