zoukankan      html  css  js  c++  java
  • Java学习笔记Iterator迭代器(Ps.instanceof的用法)

    Java有许多集合类型,如果想了解某个集合的元素,需要知道集合的类型,以调用相应的方法。在不知道集合类型的情况下,用迭代器可以查看元素的内容。

    写段代码来演示一下:

              List l=new ArrayList();

              Iterator it=l.iterator();

              while(it.hasNext())

              {

                   Object o=it.next();

                   .....

               }

    ----------------------------------------------------------------------------------------------------------------------------------------------

    这是分割线

    -----------------------------------------------------------------------------------------------------------------------------------------------

    instanceof 运算符是用来在运行时指出对象是否是特定的一个实例。instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例。
        
    用法:

    result = object instanceof class
     参数:
    result
    必选项。任意变量
    object
    必选项。任意对象表达式
    class
    必选项。任意已定义的对象类。
     说明:
    如果 objectclass 的一个实例,则 instanceof 运算符返回 true。如果 object 不是指定类的一个实例,或者 objectnull,则返回 false
  • 相关阅读:
    D. Almost All Divisors
    G
    K
    L3-016 二叉搜索树的结构 (30 分)
    D. Colored Boots(STL)
    O
    [论文]Clustering-Based Ensembles as an Alternative to Stacking
    [LeetCode] Factorial Trailing Zeroes 阶乘末尾0
    [LeetCode] Maximum Depth of Binary Tree dfs,深度搜索
    [LeetCode] Count and Say 字符串
  • 原文地址:https://www.cnblogs.com/ITEagle/p/1663892.html
Copyright © 2011-2022 走看看