最新文章列表

java enum(枚举)使用详解 + 总结

    enum 的全称为 enumeration, 是 JDK 1.5  中引入的新特性,存放在 java.lang 包中。     下面是我在使用 enum 过程中的一些经验和总结,主要包括如下内 ...
王亚龙 评论(0) 有996人浏览 2016-10-12 15:30

专为枚举类设计的集合类EnumSet

一 集合类EnumSet概述 EnumSet是一个专为枚举类设计的集合类,EnumSet中所有元素都必须是指定枚举类型的枚举值,该枚举类型在创建EnumSet时显式或隐式地指定。EnumSet的集合元素也是有序的,EnumSet以枚举值在Enum类的定义顺序来决定集合元素的顺序。 EnumSet在内部以位向量的形式存储,这种存储形式非常紧凑、高效,因此EnumSet对象占用内存很小,而且运 ...
cakin24 评论(0) 有2623人浏览 2016-09-08 21:03

【Java集合之二】Set集合

本文围绕以下六个部分展开: 一、Set集合 二、HashSet类 三、LinkedHashSet类 四、TreeSet类 五、EnumSet类 六、各个Set实现类的性能分析 一、Set集合         1. Set与Collection         Set集合与Collection除了不允许包含重复元素外,其他都完全一样。它没有提供任何额外的方法。         ...
XiangdongLee 评论(1) 有1585人浏览 2015-09-07 00:56

EnumSet的几个例子

EnumSet 是一个与枚举类型一起使用的专用 Set 实现。枚举set中所有元素都必须来自单个枚举类型(即必须是同类型,且该类型是Enum的子类)。 枚举类型在创建 set 时显式或隐式地指定。枚举 set 在内部表示为位向量。 此表示形式非常紧凑且高效。此类的空间和时间性能应该很好,足以用作传统上基于 int 的“位标志”的替换形式,具有高品质、类型安全的优势。 Enumset是个虚类,我 ...
MouseLearnJava 评论(0) 有8703人浏览 2014-11-14 16:24

枚举类型详解

枚举类型详解 一.Enum详解      1.1枚举类型的介绍   JDK1.5加入了一个全新的类型的”类”—枚举类型,为此JDK1.5引入了一个新的关键字enum,我们可以这样定义一个枚举类型。      Demo:一个最简单的枚举类   public enum ColorType { RED, BLACK, YELLOW; }        运行结果 ...
一路欢笑一路走 评论(0) 有485人浏览 2014-05-16 07:56

Item 42: Use varargs judiciously

1.  Varargs methods accept zero or more arguments of a specified type. The varargs facility works by first creating an array whose size is the number of arguments passed at the call site, then putting ...
leonzhx 评论(0) 有742人浏览 2014-04-12 23:23

Item 32: Use EnumSet instead of bit fields

1.  The java.util package provides the EnumSet class to efficiently represent sets of values drawn from a single enum type. This class implements the Set interface, providing all of the richness, type ...
leonzhx 评论(0) 有478人浏览 2014-04-04 19:13

Item 31: Use instance fields instead of ordinals

1.  All enums have an ordinal method, which returns the numerical position of each enum constant in its type.   2.  Never derive a value associated with an enum from its ordinal; store it in an ins ...
leonzhx 评论(0) 有477人浏览 2014-04-04 17:03

关于编码ansi、GB2312、unicode与utf-8的区别

关于编码ansi、GB2312、unicode与utf-8的区别 先做一个小小的试验: 在一个文件夹里,把一个txt文本(文本里包含“今天的天气非常好”这句话)分别另存为ansi、unicode、utf-8这三种编码的txt文件。然后,在该文件夹上点击右键,选择“搜索(E)…”。 搜索“天气”二字,可以搜索出ansi和unicode这两种编码的txt文件,搜索不出utf-8编码的文件。 ...
zz563143188 评论(21) 有11812人浏览 2013-04-23 11:34

EnumSet代替位域

在Android的通知栏中,我们可以通过设置Notification.flags的值来实现一些效果,比如声音,震动,或者LED灯等。通过or运算符(|)可以合并这些效果,比如我们想打开默认的声音和LED灯,可以这样实现。 notification.flags = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; // not ...
zjuttsw 评论(0) 有370人浏览 2013-02-06 20:06

JAVA EnumSet

public class enumSet { enum ALPH {M,D,F,A,E,G,W,S}; public static void main(String[] args) { // TODO Auto-generated method stub EnumSet<ALPH> all = EnumSet.allOf(ALPH.class); En ...
Genie13 评论(0) 有2078人浏览 2011-12-05 17:38

Item 1: Consider static factory methods instead of constructors

1.  One advantage of static factory methods is that, unlike constructors, they have names. BigInteger(int, int, Random), which returns a BigInteger that is probably prime, would have been better expr ...
leonzhx 评论(0) 有1251人浏览 2010-10-21 17:16

最近博客热门TAG

Java(141744) C(73651) C++(68608) SQL(64571) C#(59609) XML(59133) HTML(59043) JavaScript(54919) .net(54785) Web(54514) 工作(54118) Linux(50905) Oracle(49875) 应用服务器(43289) Spring(40812) 编程(39454) Windows(39381) JSP(37542) MySQL(37267) 数据结构(36424)

博客人气排行榜

    博客电子书下载排行

      >>浏览更多下载

      相关资讯

      相关讨论

      Global site tag (gtag.js) - Google Analytics