1. 获取系统时间:
Swift: Date().timeIntervalSince1970 这个单位是秒。
Java: System.currentTimeMillis()
2。字典:
Swift:
定义: var Frq1:NSMutableDictionary = NSMutableDictionary()
取值:Frq1.value(forKey: Ch) as!Int
赋值:Frq1.setValue(N,forKey:Ch)
Java:
定义:Map<String,Integer> Frq1;
取值:Frq1.get(Ch);
赋值:Frq1.put(Ch,N);
3。二维数组:
Swift:
var mCur1 = [[String]]()
var mCur1Seg = [String]()
mCur1.append(mCur1Seg)
Java:
ArrayList<ArrayList<String>> mCur2;
ArrayList<String> mCur2Seg = newArrayList<String>();
mCur2.add(mCur2Seg);
两者对应操作:
mCur1.append() mCur2.add()
mCur1.count mCur2.size()
mCur1[idx] mCur2.get(idx)
mCur1.removeAll() mCur2.clear()
mCur1.Last! mCur2.get(mCur2.size()-1)
另:Swift 还有 NSMutableArray 相当于 Java ArrayList,添加元素都是 add
4。取字符串长度:
Swift: str.characters.count
Java: str.length()
5。数字转文本:
Swift: "\(num)"
Java: String.valueOf(num)
6。集合:
Swift:
let set=NSMutableSet(array: sset)
var netSet = set.allObjects as! [your class]
Java:
Set<String> set = new LinkedHashSet<your class>();
set.addAll(sset);
netSet.clear();
netSet.addAll(set);