版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QQlwx/article/details/52813424
Java 编程—-(二.中级)
1. 数字与字符串之间的处理
String转int
int i = Integer = Integet.parseInt(String);
转二进制
Integer.toBinaryString(int);
Integer.toHexString(int);
Integer.toOctalString(int);
System类
使用currentTimeMills()计时程序
long start = System.currentTimeMills();
......
long end = System.currentTimeMills();
中间时间为(end - start);
2.Java.util
ArrayList
ArrayList<String> al = new ArrayList<String>;
al.add("A");
al.add("B");
sout(al);
结果显示为[A,B];
从ArrayList 获取数组
ArrayList<Integer> al = new ArrayList<Integer>;
al.add(1);
al.add(2);
Integer in[] = new Integer[al.size()];
in = al.toArray(ia);
LinkedList 链表数据结构
HashSet类
哈希表使用称之为散列的机制存储信息,在散列机制中,键的信息勇于确定唯一的值,称为哈希码。然后将哈希码用作索引,在索引位置存储与键关联的数据
HashSet不能保证元素的顺序
LinkedHashSet类按添加的顺序显示
TreeSet类 会排序再显示
Collection | 集合 |
---|---|
Deque | 扩展Queue以处理双端队列 |
List | 扩展Collection 以处理序列 |
Queue | 队列 |
Set | 处理集合,集合中的元素必须唯一 |
SortedSet | 已排序 |
3.使用迭代器访问集合
ArrayList<> al;
Iterator<String> itr = al.iterator();
while(itr.hasNext(){
String n = itr.next();
}
Boolean hasNext();
E next();
使用for-each 循环替代迭代器
ArrayList<Integer> al;
al.add(1);
for(int v:al)
sout(v);
4.使用映射
interface Map<k,v>
键值映射
Map.Entry接口
Set<Map.Entry<K,V>> entrySet()
返回包含映射中的所有条目的Set 对象
HashMap<String,Double> hm = new ...
hm.put("jhon",124.32);
Set<Map.Entry<String,Double>> set = hm.entrySet();
for(MapEntry<String,Double> me:set){
String key = me.getKey();
String value = me.getVlaue();
}
double h = hm.get("jhon");
Array类 ,数组
Vector 类
Stack类
5.Properties类 属性类
Propeprties cap = new Properties();
cap.put("1","1");
Set<?> states =cap .keySet();
for(Object name:states)
sout(cap.getProperty((String)name));
使用Store()和load();
6.一些实用类
- Date类
- Calendar类
- TimeZone类
- Local类
- Random类
- Currency //货币
- Formatter
- Scanner类
- Java.util.zip
7.Java.io 输入输出,文件
File类
- File file = new File(“a.txt”);
- Boolean renameTo(File newName) 重命名
- Boolean delete()
字节流
- InputStream类
- outStream类
String source = "I will love you ,z";
Byte buf[] = source.getBytes();
FileOutputStream fo;
fo.write(buf);
字符流
- Reader类
- Writer类
- FileReader类
- FileWriter类
Serializable接口 可串行化
可将class类转化为流
探究NIO
正则表达式和模式匹配
Patter类
Matcher类
Patter pat = Patter.compile("java");
Matcher mat = pat.matcher("java");
if(mat.matches())
mat.find();