、迭代器简介(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构。迭代器通常被称为“轻量级”对象,因为创建它的代价小。 Java中的Iterator功能比较简单,并且只能单向移动: (1) 使用方法iterator()要求容器返回一个Iterator。第一次调用Iterator的next()方法时,它返回序列的第一个元素。注意:iterator()方法是java.lang.Iterable接口,被Collect...
作者最近研究框架底层代码过程中感觉自己基础不太牢固,于是写了一点案例,以防日后忘记 接口类:Animals1publicinterface Animals {
23publicvoid eat();
4 }package cn.chenc.study.entity;publicinterface InterfaceFactory {public String show(int i);} 实体类:Personpackage cn.chenc.study.entity;import java.lang.reflect.Proxy;publicclass Person implements Animals {private String name;privateint age;public Pe...
定义list并将数组放入其中:List<Integer> temp = new ArrayList<Integer>();List<String> temp = new ArrayList<String>();获得集合内元素个数:list.size();添加元素:默认添加:list.add(e);指定下标添加(添加后下标后的元素向后挪一位):list.add(index,e);如果我们得到的List还想要增删,那么可以用addAll方法 String[] str = {"1", "2", "3", }; List<String> strArray = new ArrayList<String>(); st...
用法一:常量在JDK1.5 之前,我们定义常量都是: public static fianl.... 。现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法。publicenum Color { RED, GREEN, BLANK, YELLOW
} 用法二:switchJDK1.6之前的switch语句只支持int,char,enum类型,使用枚举,能让我们的代码可读性更强。enum Signal {GREEN, YELLOW, RED}publicclass TrafficLight {Signal color = Signal.RED;publicv...
将非Unicode编码字符转化为Unicode编码的字符,即国际化。
语法:native2ascii [options] [inputfile [outputfile]]
描述:如果outputfile没有指定,标准输出将用于结果输出;如果inputfile没有指定,标准输入设备将用于输入。
参数
-reverse
使用该参数将Unicode编码字符转换为本地编码字符
-encoding encoding_name
用于指定转化时使用的字符编码。默认编码从系统属性file.encoding获取。后面的表格式字符编码,指定encoding_na...
java.util package has public interface Iterator and contains three methods:boolean hasNext(): It returns true if Iterator has more element to iterate.Object next(): It returns the next element in the collection until the hasNext()method return true. This method throws ‘NoSuchElementException’ if there is no next element.void remove(): It removes the current element in the collection. This method...
1、定义:return 从字面上的看就是返回,官方定义return语句将终止当前函数并返回当前函数的值,可以看下下面的示例代码:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> function func1(){ while (true){ return 1; } }; alert(func1()); </script></head><body></body></html>可以看到我在函数里面写了个死循环,然后在下...
/** * Java Me-List控件的用法案例 */package com.xushouwei.cn;import java.io.IOException;import javax.microedition.lcdui.Choice;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.List;import javax.microedition.m...
参考视频:http://www.imooc.com/video/6430JavaScript中的this比较灵活,也是让很多初学者摸不到头脑,那么根据在不同的环境下,在同一个函数,不同的调用方式下,那么这个this也有可能是不同的。我们先来看,全局作用于下的this。全局的this(浏览器)console.log(this.document===documet);//trueconsole.log(this===window);//truethis.a=37;console.log(window.a);//37全局作用域下的this一般指的是全局对象,在浏览器里面一般指...
我们经常要将数字进行格式化,比如取2位小数,这是最常见的。Java 提供 DecimalFormat 类,帮你用最快的速度将数字格式化为你需要的样子。下面是一个例子: importjava.text.DecimalFormat; publicclassTestNumberFormat{ publicstaticvoidmain(String[]args){ doublepi=3.1415927; //圆周率 //取一位整数 System.out.println(newDecimalFormat("0").format(pi)); //3 //取一位整数和两位小数 System.out.println(ne...
我们可以基于一个类创建多个该类的对象,每个对象都拥有自己的成员,互相独立。然而在某些时候,我们更希望该类所有的对象共享同一个成员。此时就是static大显身手的时候了。 Java中被static修饰符修饰的成员称为静态成员或类成员。它属于整个类所有,而不是某个对象所有,即被类的所有对象所共享。静态成员可以使用类名直接访问,也可以使用对象名进行访问。当然,鉴于他作用的特殊性更推荐用类名访问。 使用static修...
1. 子类的构造函数如果要引用super的话,必须把super放在函数的首位.class Base { Base() { System.out.println("Base"); }} public class Checket extends Base { Checket() { super();//调用父类的构造方法,一定要放在方法的首个语句 System.out.println("Checket"); } public static void main(String argv[]) { Checket c = new Checket(); }} 如果想用super继承父类...
在java中提供了大数字的操作类,即java.math.BinInteger类和java.math.BigDecimal类。这两个类用于高精度计 算,其中BigInteger类是针对大整数的处理类,而BigDecimal类则是针对大小数的处理类。下边我们介绍BigDecimal类: BigDecimal的实现利用到了BigInteger,不同的是BigDecimal加入了小数的概念。一般的float型和Double型数据只可 以用来做科学计算或者是工程计算,由于在商业计算中,要求的数字精度比较高,所以要用到java.m...
1、reduce函数用法:$(function(){// arrowMouseOver();Array.prototype.reduce=null; //将内置reduce函数设置为nullvar eleResult=document.getElementById("result");console.log=function(result){var text=document.createTextNode(result);var br=document.createElement("br");//var name=document.createAttribute("data-name"); eleResult.appendChild(text);eleResult.appendChild(br);//br.setAttribute(name,"z...
正则表达式是一种可以用于模式匹配和替换的规范,一个正则表达式就是由普通的字符(例如字符a到z)以及特殊字符(元字符)组成的文字模式,它 用以描述在查找文字主体时待匹配的一个或多个字符串。正则表达式作为一个模板,将某个字符模式与所搜索的字符串进行匹配。众所周知,在程序开发中,难免会遇到需要匹配、查找、替换、判断字符串的情况发生,而这些情况有时又比较复杂,如果用纯编码方式解决,往往会浪费程序员的时间及精力...