zoukankan      html  css  js  c++  java
  • 表达式语言--集合操作

    JAVA集合:Collection,MAP,Iterator

    Collection:List,Set

    所有集合都使用Iterator输出,而List和Set的本质区别在于,List对Collection进行了扩充,可是Set没有。

    对于每次保存一对内容的操作,使用Map集合,Map每次保存的都是Map.Entry接口对象。

    例子1,输出Collection:

    <%@ page contentType="text/html" pageEncoding="GBK"%>
    <%@ page import="java.util.*"%>
    <html>
    <head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
    <body>
    <%
        List all = new ArrayList() ;
        all.add("李兴华") ;
        all.add("www.MLDNJAVA.cn") ;
        all.add("mldnqa@163.com") ;
        request.setAttribute("allinfo",all) ;    // 集合保存在request范围
    %>
    <h3>第一个元素:${allinfo[0]}</h3>
    <h3>第二个元素:${allinfo[1]}</h3>
    <h3>第三个元素:${allinfo[2]}</h3>
    </body>
    </html>

    实际开发中的JSP文件,只关注红字部分,上面的集合操作都要放在Servlet里操作。

    例子2,输出Map:

    <%@ page contentType="text/html" pageEncoding="GBK"%>
    <%@ page import="java.util.*"%>
    <html>
    <head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
    <body>
    <%
        Map map = new HashMap() ;
        map.put("lxh","李兴华") ;
        map.put("mldn","www.MLDNJAVA.cn") ;
        map.put("email","mldnqa@163.com") ;
        request.setAttribute("info",map) ;    // 集合保存在request范围
    %>
    <h3>KEY为lxh的内容:${info["lxh"]}</h3>
    <h3>KEY为mldn的内容:${info["mldn"]}</h3>
    <h3>KEY为email的内容:${info["email"]}</h3>
    </body>
    </html>

    以上输出都是以下标输出的,想用Iterator,需要结合MVC模式来设计。

  • 相关阅读:
    Leetcode Plus One
    Leetcode Swap Nodes in Pairs
    Leetcode Remove Nth Node From End of List
    leetcode Remove Duplicates from Sorted Array
    leetcode Remove Element
    leetcode Container With Most Water
    leetcode String to Integer (atoi)
    leetcode Palindrome Number
    leetcode Roman to Integer
    leetcode ZigZag Conversion
  • 原文地址:https://www.cnblogs.com/wujixing/p/5000527.html
Copyright © 2011-2022 走看看