java set转list,数组与list的转换
读zookeeper的源码(zookeeper.java)时发现的,平时没有怎么注意:
private final ZKWatchManager watchManager;
List<String> getDataWatches() {
synchronized(watchManager.dataWatches) {
List<String> rc = new ArrayList<String>(watchManager.dataWatches.keySet());
return rc;
}
}
List<String> getExistWatches() {
synchronized(watchManager.existWatches) {
List<String> rc = new ArrayList<String>(watchManager.existWatches.keySet());
return rc;
}
}
List<String> getChildWatches() {
synchronized(watchManager.childWatches) {
List<String> rc = new ArrayList<String>(watchManager.childWatches.keySet());
return rc;
}
}
另数组与list的转换:
数组-->list
String[] userid = {"aa","bb","cc"};
List<String> userList = new ArrayList<String>();
Collections.addAll(userList, userid);
数组-->list
String[] userid = {"aa","bb","cc"};
List<String> userList = Arrays.asList(userid);
另:Arrays.asList()返回一个受指定数组支持的固定大小的列表。所以不能做Add、Remove等操作。
List list = new ArrayList(Arrays.asList(userid));这样操作就可以了。
list-->数组
List<String> strList = new ArrayList<String>();
strList.add("aa");
strList.add("bb");
Object[] objs = strList.toArray();
参考文献:
【1】http://jingyan.baidu.com/article/86f4a73e607f2937d7526972.html
【2】https://github.com/apache/zookeeper
java set转list,数组与list的转换的更多相关文章
- java中将一个字符数组赋值给另一个,两者同时变化
java中将一个字符数组赋值给另一个,两者的变化怎么是同步的?怎么才能让他们独立开? 比如有一个int[][] a 已经存在值,现在定义int[][] b=a;之后改变a的值,为何b也跟着改变?怎么才 ...
- Java 图片提取RGB数组 RGBOfCharMaps (整理)
package demo; /** * Java 图片提取RGB数组 RGBOfCharMaps (整理) * 声明: * 和ImageCombining配合使用的工具,这里是提取图片的R.G.B生成 ...
- Java之--Java语言基础组成—数组
Java语言基础组成-数组 Java语言由8个模块构成,分别为:关键字.标识符(包名.类名.接口名.常量名.变量名等).注释.常量和变量.运算符.语句.函数.数组. 本片主要介绍Java中的数组,数组 ...
- 在Java中怎样把数组转换为ArrayList?
翻译自:How to Convert Array to ArrayList in Java? 本文分析了Stack Overflow上最热门的的一个问题的答案,提问者获得了很多声望点,使得他得到了在S ...
- Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式)
Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式) 原文地址:http://alanland.iteye.com/admin/blogs/1600685(欢迎转载 ...
- JAVA中list,set,数组之间的转换详解
JAVA的list,set,数组之间的转换,主要是使用Apache Jakarta Commons Collections,具体的方法如下:import org.apache.commons.coll ...
- Java 集合 集合与数组之间的转换
Java 集合 集合与数组之间的转换 @author ixenos 数组转集合 Arrays.asList(T... a) 先给结论:用 Arrays.asList(T... a) 将数组转换成集合 ...
- Java 基础类型转换byte数组, byte数组转换基础类型
Java 基础类型转换byte数组, byte数组转换基础类型 Java类型转换 java类对象转化为byte数组
- java byte【】数组与文件读写(增加新功能)
今天在测试直接写的文章: java byte[]数组与文件读写 时,想调用FileHelper类对字节数组以追加的方式写文件,结果无论怎样竟然数据录入不全,重新看了下文件的追加模式,提供了两种方式: ...
- java.sql.SQLException之数组越界
java.sql.SQLException之数组越界 1.具体错误如下: (1)java.sql.SQLException:Parameter index out of range(0<1) ( ...
随机推荐
- 洛谷——P2446 [SDOI2010]大陆争霸
https://www.luogu.org/problem/show?pid=2446#sub 题目背景 在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的克里斯国.两个国家的人民分别 ...
- CF(438D) The Child and Sequence(线段树)
题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...
- [Javascript] Specify this using .call() or .apply()
A function's this argument is usually set implicitly, depending on how the function is called. Ordin ...
- 【剑指Offer学习】【面试题27:二叉搜索树与双向链表】
题目:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建不论什么新的结点.仅仅能调整树中结点指针的指向. 比方输入图4.12 中左边的二叉搜索树,则输出转换之后的排序现向链表. ...
- 70.nodejs操作mongodb
转自:https://www.cnblogs.com/whoamme/p/3467374.html 首先安装nodejs mongodb npm install mongodb var mongodb ...
- javafx Hanoi
Netbean java8 source code :http://files.cnblogs.com/files/rojas/HNT.zip screenshot: 1 model /* ...
- javafx KeyCombination
import javafx.application.Application; import javafx.application.Platform; import javafx.event.Actio ...
- 【Codeforces Round #457 (Div. 2) B】Jamie and Binary Sequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把n分解成二进制的形式. n=2^a0+2^a1+...+2^a[q-1] 则固定就是长度为q的序列. 要想扩展为长为k的序列. 可 ...
- 最简单的基于FFmpeg的移动端例子:Android 视频转码器
http://blog.csdn.net/leixiaohua1020/article/details/47056365
- Ternary Tree
前一篇文章介绍了Trie树.它实现简单但空间效率低.假设要支持26个英文字母,每一个节点就要保存26个指针,因为节点数组中保存的空指针占用了太多内存.让我来看看Ternary Tree. When y ...