码迷,mamicode.com
首页 > 编程语言 > 详细

java基础背诵快记

时间:2019-03-30 20:16:57      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:poll   start   settime   hashmap   复制   迭代器   cat   iterator   sea   

1、环境变量
--win
JAVA_HOME D:\java1.8
CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;
PATH ;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
--linux
sudo mkdir /usr/local/java
tar java1.8.tar.gz
sudo mv java1.8/ /usr/local/java/
sudo chown -R root:root /usr/local/java/
sudo vi /etc/profile
export JAVA_HOME=/usr/local/java/java1.8
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
source /etc/profile
echo $PATH
java -version

2、常见类型
byte:1,short:2;int:4;long:8;--1字节=8二进制位
char:2,boolean:t/f
float:0.0f,2.8e9,7
double:0.0d,9.15e18,16
0,0x,final
b,s,c->i->l->f->d

3、数组
int[] x = new int[3];
int[] x = new int[]{1,2,3};
int[] x = {1,2,3};
int[][] xx = new int[3][];
byte[] x = str.getBytes();
// Arrays工具类
Arrays.copyOf([],num);
Arrays.copyOfRange([],b,e);
Arrays.fill([],val);
Arrays.toString([]);
Arrays.asList([]);
Arrays.binarySearcher([],val);

4、字符串
valueOf,intern
charAt,indexOf,lastIndexOf
compareToIgnoreCase,equalsIgnoreCase,contentEquals(sb)
startsWith,endsWith,matches
concat,substring(b,e),replace3,trim
toUpCase,toLowerCase
split,toCharArray,getBytes
str=="" -> str.equals("")
str==null
StringBuffer,线程,大字符串
StringBuilde,非线程,大字符串
append,delete,replace,reverse

5、枚举
enum day{q,w,e}
day q = day.q;
day w = Enum.valueOf(day.class,"w");
day e = day.valueOf("w");
q.name(); -> q.toString();//q
// 加备注
enum day{q("1"),w("2"),e("3");
private String des;
private day(String des){this.des=des;}
public String getDes(){return des;}}
day.q.getDes();//1
// 统计list中每种enum存在的数量
Map<day,Integer> map=EnumMap<>(day.class);
for(Emp e:list){
day d = e.getDay();
Integer ii = map.get(d);
if(ii==null)map.put(d,1);
else map.put(d,++i);}
System.out.println(map);

6、日期时间
Date();Date(long);
getTime,setTime(long)
SimpleDateFormat sf = new SimpleDateFormat("E yyyy-MM-dd");
sf.format(date);
Calendar.getInstance();
cal.get(Calendar.DAY_OF_WEEK);
// java8
LocalDate ld = LocalDate.now();
ld = LocalDate.of("2019","03","30");
LocalDate,LocalDateTime
ZoneDateTime.of(ldt,ZoneId.of("Asia/Shanghai"));
DateTimeFormatter.ofPattern("yyyy").format(ld);
now,of,plusDays,minusDays,isBefore,isAfter,isLeapYear

7、集合
// Colletion
add,get,remove,clear,reoEach,contains
stream,parallelStream,Collections.synchronisedList
// List
ArrayList:数组,查改快,复制移动,随机存取,非线程,百万级
LinkedList:链表,增删快,遍历移动,非线程
Vector:数组,线程
// Set 自动去重
HashSet:无序,快
LinkedHAshSet:FIFO,中速
TreeSet:红黑树,有序,慢
new TreeSet<>(comparator);(a,b)->(>,0,<)
// Queue
Priority:默认排序,小先出,非线程
CocurrentLinkedQueue:无界,非阻塞,线程
ArrayBlockingQueue:有界,阻塞,线程
LinkedBlockingQueue:无界,阻塞,线程
DelayedQueue:无界,阻塞,线程,元素继承Delay
add,remove,element 一般队列
offer,poll,peek 阻塞异常
put,take 阻塞等待
// Iterator迭代器
hasNext,next,remove,forEachRemaining
// Map键值对
HashMap:无序,快
LinkedHashMap:FIFO,中速
TreeMap:红黑树,有序,慢
containsKey,containsValue
keySet,vlaues,put,get
// Colletions工具类
Colletions.sort(c,comparator);
Colletions.shuffle(c);
Colletions.reverse(c);
Colletions.swap(c,e1,e2);
Colletions.copy(c,e1,e2);
Colletions.synchronizedList...

java基础背诵快记

标签:poll   start   settime   hashmap   复制   迭代器   cat   iterator   sea   

原文地址:https://www.cnblogs.com/cuminbf/p/java.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!