獲取List中的資料的實現方法

2021-07-23 02:11:58 字數 560 閱讀 7176

大家都知道list是很好的儲存資料的集合類。

但是獲取讀取list中資料的方法你知道幾種呢!一下是我知道的方法分享給大家!

list> list = new arraylist>();

mapmap1= new hashmap();

map1.put("keyname", "1111");

map1.put("***", "5");

方法一、

for(mapmaps:list)

方法二、

for (int i = 0; i < list.size(); i++)

方法三 iterator是一種迭代器、

for(iterator> iter = list.iterator();iter.hasnext();)

方法四:

while(list.hasnext()){

mapmaps = iter.next();

system.out.println("得到的結果是name----"+maps.get("keyname")+ "\n***-----"+maps.get("***"));

Python中list的交 並 差集獲取方法示例

1.獲取兩個list 的交集 coding utf 8 方法一 a 2,3,4,5 b 2,5,8 tmp val for val in a if val in b print tmp 2,5 方法二 print list set a intersection set b 2.獲取兩個list 的並...

php獲取資料庫中資料的實現方法

廢話不多說,直接上 php header content type text html charset utf 8 字元編碼設定 servername localhost username root password root dbname web 建立連線 con mysqli www.cppcn...

php中的list方法

list 栗子一 info array coffee brown caffeine 列出所有變數 list drink,color,power info echo drink is color and power makes it special.n 列出他們的其中乙個 list drink,pow...