源代码 (source code) → 预处理器 (preprocessor) → 编译器 (compiler) → 汇编程序 (assembler) → 目标代码 (object code) →链接器 (Linker) → 可执行程序 (executables)。 java
Java基础类:ArrayList, HashMap, HashSet linux
C++ | Java | |
定义 | vector<int> vTest(50) | ArrayList vTest = new ArrayList() |
追加 |
int x = 5;
vTest.push_back( x )
|
Integer x = new Interger(5)
vTest.add( x )
|
元素个数 | vTest.size() | vTest.size() |
判断空 | vTest.empty() // TRUE为空 | vTest.isEmpty() |
插入 |
vector<int>::iterator iter;
int y = 15;
iter = vTest.begin();
vTest.insert(iter+4, y)
|
int y = 15;
vTest.add( 5, y)
|
删除 | vTest.erase( vTest.begin() ) | vTest.remove(5) |
迭代 |
vector<int>::iterator iter;
iter = vTest.begin();
int xx = 0;
while( iter != vTest.end() )
{
xx = *iter;
iter++;
}
|
iterator it = vTest.iterator(); //
取得第一个
while( it.hasNext() )
{
Integer xx = (Integer) it.next(); //
向下转换
}
|
获取 |
vTest[i]
或
vTest.at(i)
|
读取
vTest.get(i)
写入
vTest.set(i, new Integer(15));
|
清空 | vTest.clear() | vTest.clear() |
C++ | Java | |
定义 | map<string, int> mapTest | HashMap mapTest = new HashMap() |
插入 |
mapTest[ string(“hello”) ] = 1;
或者
typedef map<string,int>::value_type valType;
string str = “hello”;
mapTest.insert(valType(str, 1));
|
mapTest.put(“hello”, new Integer(1) );
|
查找 |
mapTest.count(“hello”) 判断个数
map<string,int>::iterator it;
it = mapTest.find(“hello”);
int x = (*it).second;
|
判断存在:
mapTest.containsKey()
获取
Integer x = (Integer)mapTest.get(“hello”)
|
C++ | Java | |
定义 |
vector<string> vec; //假设已插入数据
vector<string>::iterator it;
|
ArrayList vec = new ArrayList(); //假设已插入数据
Iterator it = vec.iterator();
|
排序 | sort(vec.begin(), vec.end()) | Collections.sort(vec); |
查找 |
find(vec.begin(), vec.end(), “hello”)
|
二分查找:
int pos = Collections.binarySearch(vec, “hello”);
|
复制 |
int ia[] = {1,2,3,4,5}
vector<int> vec;
copy(ia, ia+5, back_inserter(vec));
|
C++ | Java | |
定义 |
string str = “cpp string”;
string str(“hello”);
转换为
C
风格字符串
str.c_str();
|
String str = “java string” |
追加 |
str = str + “world”;
str.append(“world”);
|
str = “hello” + “world”;
str.concat(“world”);
|
长度 | str.length() | str.length(); |
比较 |
str.compare(otherstr);
判断相等
str == otherstr
|
str.CompareTo(otherstr);
判断相等
:
str.equals(otherstr);
正则表达式匹配
str.matches(“^#(.)+$”);
|
子串 | str.substr(5,6) //第5个字符,长度6 |
str.substring(5,8) //
第
5
到第
8
个字符
分割:
String str = “CHN,JPN,RUS”;
String vecstr[];
vecstr = str.split(“,”);
结果为
String
数组
“CHN”, “JPN”, “RUS”
|
查找 |
int idx = str.find(“cpp”);
if( idx != string::npos ) {
... ... //
找到位置
}
查找第一个出现
0~9
字符的位置
int idx = find_first_of(str, “1234567890”);
|
int idx = str.indexOf(“cpp”);
if( idx != -1) {
.. ...
}
|
清空 | str.clear() | str.clear() |
http://www.ibm.com/developerworks/cn/linux/management/configuration/ 程序员