做網(wǎng)站外包工作怎么樣360應(yīng)用商店
一、流程控制
1、概念
//1.if//2.if...else//3.if...else if...else...//4.switch//5.跳出循環(huán)體:break和continue
2、語法
//1. ifif(條件表達(dá)式){//執(zhí)行代碼塊}//2.if...elseif(條件表達(dá)式){//條件表達(dá)式為真執(zhí)行的代碼塊} else {//條件表達(dá)式為假執(zhí)行的代碼塊}//3.if...else if...else...if(條件表達(dá)式){//條件表達(dá)式符合條件執(zhí)行的代碼塊} else if(條件表達(dá)式) {//條件表達(dá)式符合條件執(zhí)行的代碼塊} else {//默認(rèn)執(zhí)行的代碼塊}//4.switchswitch(expression){case value ://語句break; //可選case value ://語句break; //可選//你可以有任意數(shù)量的case語句default : //可選//語句}
3、案例
public static void main (String[] args) {int a = 15;//1.ifif(a<6){System.out.println("簡單的判斷語句");}//2.if...else...if(a<6){System.out.println("if...else... 條件表達(dá)式為真");} else {System.out.println("if...else... 條件表達(dá)式為假");}//3.if...else if...else...if(a<6){System.out.println("if...else if...else... 條件表達(dá)式為真");} else if(a==6){System.out.println("if...else if...else... 條件表達(dá)式為假");} else {System.out.println("默認(rèn)執(zhí)行的代碼塊");}//4.switchint a = 10;switch(a){case 1:System.out.println("得分" + a); break;case 2:System.out.println("得分" + a); break;case 3:System.out.println("得分" + a); break;case 4:System.out.println("得分" + a); break;case 5:System.out.println("得分" + a); break;case 6:System.out.println("得分" + a); break;default:System.out.println("沒獲取得分"); }
二、單列集合和雙列集合
1、Java 中單列集合的組成方式由下面的方式構(gòu)成
- HashSet 的底層數(shù)據(jù)結(jié)構(gòu)是哈希表,哈希表主要由
hashCode()
和equals()
兩個(gè)方法保證唯一性的,首先判斷hashCode()
的值是否相同,如果相同繼續(xù)執(zhí)行equals()
方法,(看返回的結(jié)果:如果返回true
:不添加,返回false
:添加)。如果返回不同,直接存入。 - LinkedHashSet 的底層數(shù)據(jù)結(jié)構(gòu)是鏈表和哈希表組成,鏈表保證元素的有序;哈希表保證元素的唯一性。
- TreeSet 底層數(shù)據(jù)結(jié)構(gòu)是紅黑樹。
- ArrayList 底層數(shù)據(jù)結(jié)構(gòu)是數(shù)組,查詢速度快,增刪慢,但是線程不安全,效率高。數(shù)據(jù)是有序、可重復(fù)。
- Vector 底層數(shù)據(jù)結(jié)構(gòu)是數(shù)組,查詢快,增刪慢。線程安全、效率低。數(shù)據(jù)是有序、可重復(fù)。
- LinkedList 底層數(shù)據(jù)結(jié)構(gòu)是鏈表,查詢慢,增刪快。存儲(chǔ)數(shù)據(jù)的特點(diǎn)是數(shù)據(jù)有序、可重復(fù)。
2、Java 中雙列集合的組成方式由下面的方式構(gòu)成
- Map 雙列集合的特點(diǎn)是數(shù)據(jù)結(jié)構(gòu)只對 key 值有效和值無關(guān)。存儲(chǔ)的形式是以
鍵值
對的形式存儲(chǔ)元素的,鍵
是唯一的,值
可能會(huì)重復(fù)。 - HashMap 底層數(shù)據(jù)結(jié)構(gòu)是哈希表,線程不安全、效率高。哈希表主要依賴的兩個(gè)方法:
hashCode()
和equals()
執(zhí)行的順序是首先判斷hashCode()
值是否相同。如果相同繼續(xù)執(zhí)行equals()
然后再看返回結(jié)果, 如果返回 true 說明元素重復(fù),不添加;如果返回 false 就直接添加到集合. - LinkedHashMap 底層數(shù)據(jù)結(jié)構(gòu)是鏈表和哈希表組成,鏈表保證元素的有序;哈希表保證數(shù)據(jù)的唯一性。
- Hashtable 底層數(shù)據(jù)結(jié)構(gòu)是哈希表,線程安全,效率低。
- TreeMap 底層數(shù)據(jù)結(jié)構(gòu)是紅黑樹。
三、聲明數(shù)組
//數(shù)組://語法:type [] arrayName;或者type arrayName [];//初始化://靜態(tài)初始化://方式1int [] arr = new int[]{5, 6, 7, 8, 9};System.out.println(arr[1]);//方式2int [] arrName = {1, 2, 3, 4, 6};//動(dòng)態(tài)初始化:int [] arrs = new int[5];//存值&獲取值://獲取值arrayName[索引位置]//存值arrayName[索引位置] = 值;
//循環(huán)// 1.whilewhile( 布爾表達(dá)式 ) {//循環(huán)內(nèi)容}//2.do...while...//循環(huán)至少執(zhí)行一次do {//循環(huán)內(nèi)容} while(條件表達(dá)式);//3.普通for循環(huán)for(初始化; 布爾表達(dá)式; 更新) {//執(zhí)行代碼塊}//4.增強(qiáng)forfor(聲明語句 : 表達(dá)式) {//執(zhí)行代碼塊}
四、容器的聲明和遍歷
//HashSetpackage com.tsing.extend.demo9;import java.util.HashSet;public class DemoHashSet {public static void main(String[] args) {HashSet<String> hs = new HashSet<String>();//addhs.add("測試1");hs.add("測試1");hs.add("測試2");hs.add("測試3");//deletehs.remove("測試2");//update//這個(gè)需要配合查詢需要?jiǎng)h除的元素,然后執(zhí)行刪除操作,最后將新的數(shù)據(jù)添加進(jìn)去。//searchfor (String str : hs) {System.out.println(str);}}}//TreeSetpackage com.tsing.extend.demo9;import java.util.TreeSet;public class DemoTreeSet {public static void main(String[] args) {TreeSet<String> ts = new TreeSet<String>();//addts.add("ceshi1");ts.add("ceshi2");ts.add("ceshi3");ts.add("ceshi3");ts.add("ceshi4");//deletets.remove("ceshi4");//update//這個(gè)需要配合查詢需要?jiǎng)h除的元素,然后執(zhí)行刪除操作,最后將新的數(shù)據(jù)添加進(jìn)去。//searchfor (String str : ts) {System.out.println(str);}}}//ArrayListpackage com.tsing.extend.demo9;import java.util.ArrayList;public class DemoArrayList {public static void main(String[] args) {ArrayList<String> al = new ArrayList<String>();//addal.add("ceshi1");al.add("ceshi2");al.add("ceshi3");al.add("ceshi3");al.add("ceshi4");//deleteal.remove("ceshi1");al.remove(2);//根據(jù)索引刪除//update//這個(gè)需要配合查詢需要?jiǎng)h除的元素,然后執(zhí)行刪除操作,最后將新的數(shù)據(jù)添加進(jìn)去。//searchfor (String str : al) {System.out.println(str);}}}//Vectorpackage com.tsing.extend.demo9;import java.util.Vector;public class DemoVector {public static void main(String[] args) {Vector<String> v = new Vector<String>();//addv.add("ceshi1");v.add("ceshi2");v.add("ceshi3");v.add("ceshi4");v.add("ceshi4");//deletev.remove("ceshi1");v.remove(3);//根據(jù)索引刪除數(shù)據(jù)//update//這個(gè)需要配合查詢需要?jiǎng)h除的元素,然后執(zhí)行刪除操作,最后將新的數(shù)據(jù)添加進(jìn)去。//searchfor (String str : v) {System.out.println(str);}}}//LinkedListpackage com.tsing.extend.demo9;import java.util.LinkedList;public class DemoLinkedList {public static void main(String[] args) {LinkedList<String> ll = new LinkedList<String>();//addll.add("ceshi1");ll.add("ceshi2");ll.add("ceshi3");ll.add("ceshi4");ll.add("ceshi5");//deletell.remove(0);ll.remove("ceshi5");//updatell.set(2, "測試2");//searchfor (String str : ll) {System.out.println(str);}}}//HashMappackage com.tsing.extend.demo9;import java.util.HashMap;import java.util.Map;import java.util.Set;public class DemoHashMap {public static void main(String[] args) {HashMap<String,String> map = new HashMap<String, String>();//addmap.put("1", "值1");map.put("2", "值2");map.put("3", "值3");map.put("4", "值4"); //這個(gè)覆蓋掉map.put("4", "值5"); //deletemap.remove("1");//updatemap.put("2", "修改后的值2");//searchSet<Map.Entry<String,String>> en = map.entrySet();for (Map.Entry<String, String> entry : en) {System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());}}}//HashTablepackage com.tsing.extend.demo9;import java.util.Hashtable;import java.util.Map;import java.util.Set;public class DemoHashtable {public static void main(String[] args) {Hashtable<String, String> hb = new Hashtable<String, String>();//addhb.put("1", "值1");hb.put("2", "值2");hb.put("3", "值3");hb.put("4", "值4"); //這個(gè)覆蓋掉hb.put("4", "值5"); //deletehb.remove("1");//updatehb.put("2", "修改后的值2");//searchSet<Map.Entry<String,String>> en = hb.entrySet();for (Map.Entry<String, String> entry : en) {System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());}}}//TreeMappackage com.tsing.extend.demo9;import java.util.Map;import java.util.Set;import java.util.TreeMap;public class DemoTreeMap {public static void main(String[] args) {TreeMap<String, String> tm = new TreeMap<String, String>();//addtm.put("1", "值1");tm.put("2", "值2");tm.put("3", "值3");tm.put("4", "值4"); //這個(gè)覆蓋掉tm.put("4", "值5"); //deletetm.remove("1");//updatetm.put("2", "修改后的值2");//searchSet<Map.Entry<String,String>> en = tm.entrySet();for (Map.Entry<String, String> entry : en) {System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());} }}//循環(huán)//1.whilepublic static void main (String[] args) {int x = 10;while(x < 20) {System.out.print("value of x : " + x );x++;System.out.print("\n");}}//2.do...while...public static void main (String[] args) {int x = 10;do{System.out.print("value of x : " + x );x++;System.out.print("\n");} while (x < 12);}//3.forpublic static void main (String[] args) {for(int i = 0; i <= 10; i++){System.out.println("執(zhí)行了第" + i + "次");}}//4.增強(qiáng)forpublic static void main (String[] args) {String[] names = { "李棟", "王彥舒", "老子恨你" };for( String name : names ) {System.out.println(name);};}