陣列練習題
除夕也別忘了學習啊,今天做兩題(而且是從後往前做),繼續保持新鮮動力學習Scala!
10. 引入java.awt.datatransfer._,構建一個型別為SystemFlavorMap型別的物件:
val flavors = SystemFlavorMap.getDefaultFlavorMap().asInstanceOf[SystemFlavorMap]
然後,以DataFlavor.imageFlavor為引數,呼叫該物件的getNativesForFlavor方法。
以Scala的Buffer儲存返回值,看看是什麼。
Ans:
scala> import scala.collection.JavaConversions.asScalaBuffer
import scala.collection.JavaConversions.asScalaBuffer
scala> import scala.collection.mutable.Buffer
import scala.collection.mutable.Buffer
scala> val flavors = SystemFlavorMap.getDefaultFlavorMap().asInstanceOf[SystemFlavorMap]
flavors: java.awt.datatransfer.SystemFlavorMap = java.awt.datatransfer.SystemFlavorMap@19cad9d
scala> val cmd : Buffer[String] = flavors.getNativesForFlavor(DataFlavor.imageFlavor)
cmd: scala.collection.mutable.Buffer[String] = Buffer(PNG, JFIF, DIB, ENHMETAFILE, METAFILEPICT)
scala> cmd
res0: scala.collection.mutable.Buffer[String] = Buffer(PNG, JFIF, DIB, ENHMETAFILE, METAFILEPICT)
9. 建立一個由java.util.TimeZone.getAvailableIDs返回的時區集合,判斷條件是它們在美洲,去掉“America/”字首並排序。
Ans:
scala> import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArrayBuffer
scala> val tz_new = for (tz <- java.util.TimeZone.getAvailableIDs if tz.startsWith("America/")) yield {
| tz.drop("America/".length)
| }
tz_new: Array[String] = Array(Adak, Atka, Anchorage, Juneau, Nome, Sitka, Yakutat, Dawson, Ensenada, Los_Angeles, Metlakatla, Sant
a_Isabel, Tijuana, Vancouver, Whitehorse, Boise, Cambridge_Bay, Chihuahua, Creston, Dawson_Creek, Denver, Edmonton, Hermosillo, In
uvik, Mazatlan, Ojinaga, Phoenix, Shiprock, Yellowknife, Bahia_Banderas, Belize, Cancun, Chicago, Costa_Rica, El_Salvador, Guatema
la, Indiana/Knox, Indiana/Tell_City, Knox_IN, Managua, Matamoros, Menominee, Merida, Mexico_City, Monterrey, North_Dakota/Beulah,
North_Dakota/Center, North_Dakota/New_Salem, Rainy_River, Rankin_Inlet, Regina, Resolute, Swift_Current, Tegucigalpa, Winnipeg, At
ikokan, Bogota, Cayman, Coral_Harbour, Detroit, Fort_Wayne, Grand_Turk, Guayaquil, Havana, Indiana/Indianapolis, Indiana/Marengo,
Indiana/Petersbur...
scala> tz_new.sortWith(_ < _)
res5: Array[String] = Array(Adak, Anchorage, Anguilla, Antigua, Araguaina, Argentina/Buenos_Aires, Argentina/Catamarca, Argentina/
ComodRivadavia, Argentina/Cordoba, Argentina/Jujuy, Argentina/La_Rioja, Argentina/Mendoza, Argentina/Rio_Gallegos, Argentina/Salta
, Argentina/San_Juan, Argentina/San_Luis, Argentina/Tucuman, Argentina/Ushuaia, Aruba, Asuncion, Atikokan, Atka, Bahia, Bahia_Band
eras, Barbados, Belem, Belize, Blanc-Sablon, Boa_Vista, Bogota, Boise, Buenos_Aires, Cambridge_Bay, Campo_Grande, Cancun, Caracas,
Catamarca, Cayenne, Cayman, Chicago, Chihuahua, Coral_Harbour, Cordoba, Costa_Rica, Creston, Cuiaba, Curacao, Danmarkshavn, Dawso
n, Dawson_Creek, Denver, Detroit, Dominica, Edmonton, Eirunepe, El_Salvador, Ensenada, Fort_Wayne, Fortaleza, Glace_Bay, Godthab,
Goose_Bay, Grand_...
或一條語句搞掂:
scala> (for (tz <- java.util.TimeZone.getAvailableIDs if tz.startsWith("America/")) yield tz.drop("America/".length)).sortWith(_ < _)
res6: Array[String] = Array(Adak, Anchorage, Anguilla, Antigua, Araguaina, Argentina/Buenos_Aires, Argentina/Catamarca, Argentina/
ComodRivadavia, Argentina/Cordoba, Argentina/Jujuy, Argentina/La_Rioja, Argentina/Mendoza, Argentina/Rio_Gallegos, Argentina/Salta
, Argentina/San_Juan, Argentina/San_Luis, Argentina/Tucuman, Argentina/Ushuaia, Aruba, Asuncion, Atikokan, Atka, Bahia, Bahia_Band
eras, Barbados, Belem, Belize, Blanc-Sablon, Boa_Vista, Bogota, Boise, Buenos_Aires, Cambridge_Bay, Campo_Grande, Cancun, Caracas,
Catamarca, Cayenne, Cayman, Chicago, Chihuahua, Coral_Harbour, Cordoba, Costa_Rica, Creston, Cuiaba, Curacao, Danmarkshavn, Dawso
n, Dawson_Creek, Denver, Detroit, Dominica, Edmonton, Eirunepe, El_Salvador, Ensenada, Fort_Wayne, Fortaleza, Glace_Bay, Godthab,
Goose_Bay, Grand_...
相關文章
- JAVA 陣列 練習Java陣列
- 二維陣列練習陣列
- Java學習之陣列練習Java陣列
- 六,陣列筆記及相關練習題大全陣列筆記
- 指標陣列練習排列字串指標陣列字串
- Java學習筆記——陣列練習(七)Java筆記陣列
- leetcode陣列練習題2:283. 移動零LeetCode陣列
- 習題8-3 陣列迴圈右移 及 練習7-8 方陣迴圈右移陣列
- (合併 重疊陣列)練習容器的用法陣列
- Java陣列小練筆Java陣列
- 樹狀陣列模板+習題集陣列
- C的二維陣列(習題)陣列
- 笨辦法學C 練習34:動態陣列陣列
- 笨辦法學C 練習8:大小和陣列陣列
- 二維陣列和函式綜合程式設計練習陣列函式程式設計
- 陣列學習陣列
- cuda矩陣練習(一)矩陣
- 陣列題目陣列
- 陣列 題目陣列
- 利用陣列處理批次資料之習題陣列
- 陣列的學習陣列
- plsql陣列學習SQL陣列
- 新手練習:Python練習題目Python
- JS陣列專題1️⃣ ➖ 陣列扁平化JS陣列
- golang 陣列面試題Golang陣列面試題
- php陣列問題PHP陣列
- js練習(一)找出元素item在給定陣列arr中的位置JS陣列
- 大資料之JAVA基礎(五):迴圈和陣列方法練習大資料Java陣列
- mysql練習題MySql
- TypeScript 練習題TypeScript
- java練習題Java
- SQL 練習題SQL
- SQL練習題SQL
- 面試題:陣列按列排序的問題面試題陣列排序
- E - 樹狀陣列 1【GDUT_22級寒假訓練專題五】陣列
- 每日一練(46):兩個陣列的交集陣列
- 學習JSON陣列JSON陣列
- PHP學習3——陣列PHP陣列