1.find /tmp/ -type f -name "*.txt"
---------------------------------------------
2. 若要附加一段文字到某個檔案, 可用
echo "XXX" >> file
此處要注意是 >> 代表附加
------------------------------------------------
xargs 將前方的輸出變成 argument
1. [Andy@localhost test2]$ ls | xargs -i mv {} ../test1/
2010年4月22日 星期四
Variable Lenght
1. FUN(Type... Name)
2. caller (TYPE A, TYPE B)
3. REceive
for (TYPE a: Name) // is a array
{
...
}
// Fig. 7.20: VarargsTest.java
2 // Using variable-length argument lists.
3
4 public class VarargsTest
5 {
6 // calculate average
7 public static double average( double... numbers )
8 {
9 double total = 0.0; // initialize total
10
11 // calculate total using the enhanced for statement
12 for ( double d : numbers )
13 total += d;
14
15 return total / numbers.length;
16 } // end method average
17
18 public static void main( String args[] )
19 {
20 double d1 = 10.0;
21 double d2 = 20.0;
22 double d3 = 30.0;
23 double d4 = 40.0;
24
25 System.out.printf( "d1 = %.1f\nd2 = %.1f\nd3 = %.1f\nd4 = %.1f\n\n",
26 d1, d2, d3, d4 );
27
28 System.out.printf( "Average of d1 and d2 is %.1f\n",
29 average( d1, d2 ) );
30 System.out.printf( "Average of d1, d2 and d3 is %.1f\n",
31 average( d1, d2, d3 ) );
32 System.out.printf( "Average of d1, d2, d3 and d4 is %.1f\n",
33 average( d1, d2, d3, d4 ) );
34 } // end main
35 } // end class VarargsTest
=== Reference ===
1. http://www.deitel.com/articles/java_tutorials/20060106/VariableLengthArgumentLists.html
2. caller (TYPE A, TYPE B)
3. REceive
for (TYPE a: Name) // is a array
{
...
}
// Fig. 7.20: VarargsTest.java
2 // Using variable-length argument lists.
3
4 public class VarargsTest
5 {
6 // calculate average
7 public static double average( double... numbers )
8 {
9 double total = 0.0; // initialize total
10
11 // calculate total using the enhanced for statement
12 for ( double d : numbers )
13 total += d;
14
15 return total / numbers.length;
16 } // end method average
17
18 public static void main( String args[] )
19 {
20 double d1 = 10.0;
21 double d2 = 20.0;
22 double d3 = 30.0;
23 double d4 = 40.0;
24
25 System.out.printf( "d1 = %.1f\nd2 = %.1f\nd3 = %.1f\nd4 = %.1f\n\n",
26 d1, d2, d3, d4 );
27
28 System.out.printf( "Average of d1 and d2 is %.1f\n",
29 average( d1, d2 ) );
30 System.out.printf( "Average of d1, d2 and d3 is %.1f\n",
31 average( d1, d2, d3 ) );
32 System.out.printf( "Average of d1, d2, d3 and d4 is %.1f\n",
33 average( d1, d2, d3, d4 ) );
34 } // end main
35 } // end class VarargsTest
=== Reference ===
1. http://www.deitel.com/articles/java_tutorials/20060106/VariableLengthArgumentLists.html
Map to Iterator
1. Map have the basic put(key, value) and get (key) basic method
2. you can using the iterator of entry to iterator it
{{{
NavigableMap nm = r.getFamilyMap(Bytes.toBytes("data"));
byte[] value = nm.get(Bytes.toBytes("2"));
String valueStr = Bytes.toString(value);
System.out.println("Get: Qualify:value is " + "2" + ":" + valueStr);
// using iterator
Iterator< entry > it = nm.entrySet().iterator();
while (it.hasNext()) {
Entry pairs = it.next();
System.out.println(Bytes.toString(pairs.getKey()) + " = " + Bytes.toString(pairs.getValue()));
}
}}}
2. you can using the iterator of entry to iterator it
{{{
NavigableMap
byte[] value = nm.get(Bytes.toBytes("2"));
String valueStr = Bytes.toString(value);
System.out.println("Get: Qualify:value is " + "2" + ":" + valueStr);
// using iterator
Iterator< entry
while (it.hasNext()) {
Entry
System.out.println(Bytes.toString(pairs.getKey()) + " = " + Bytes.toString(pairs.getValue()));
}
}}}
2010年4月21日 星期三
Object Reference
在 java 中所有的物件皆用 Reference 表示,
如 assign A 給 B, 則 A 和 B 指向相同區塊.
{{{
import andy.Point;
public class ObjectReference {
public static void main(String[] args) {
Point p1 = new Point();
Point p2 = p1;
Object ob1 = p1;
System.out.println("p1: " + p1 + ", p2: " + p2 + ", Object p1" + ob1);
}
}
}}}
{{{
[Andy@t-ap188 row]$ java ObjectReference
p1: andy.Point@3e25a5, p2: andy.Point@3e25a5, Object p1: andy.Point@3e25a5
}}}
如 assign A 給 B, 則 A 和 B 指向相同區塊.
{{{
import andy.Point;
public class ObjectReference {
public static void main(String[] args) {
Point p1 = new Point();
Point p2 = p1;
Object ob1 = p1;
System.out.println("p1: " + p1 + ", p2: " + p2 + ", Object p1" + ob1);
}
}
}}}
{{{
[Andy@t-ap188 row]$ java ObjectReference
p1: andy.Point@3e25a5, p2: andy.Point@3e25a5, Object p1: andy.Point@3e25a5
}}}
static
當 java 執行時會 load statictest 建立 statictest static varibale, 所以才能會
能執行 static Point
{{{
import andy.Point;
public class Statictest {
static Point pb = new Point();
public static void main(String[] args) {
Statictest.pb.x = 6;
Statictest.pb.y = 10;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
}}}
{{{
[Andy@t-ap188 row]$ javac -verbose Statictest.java
[parsing started Statictest.java]
[parsing completed 31ms]
[search path for source files: .]
[search path for class files: /usr/java/jdk1.6.0_19/jre/lib/resources.jar,/usr/java/jdk1.6.0_19/jre/lib/rt.jar,/usr/java/jdk1.6.0_19/jre/lib/sunrsasign.jar,/usr/java/jdk1.6.0_19/jre/lib/jsse.jar,/usr/java/jdk1.6.0_19/jre/lib/jce.jar,/usr/java/jdk1.6.0_19/jre/lib/charsets.jar,/usr/java/jdk1.6.0_19/jre/classes,/usr/java/jdk1.6.0_19/jre/lib/ext/localedata.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunpkcs11.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunjce_provider.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/dnsns.jar,.]
[loading ./andy/Point.class]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking Statictest]
[wrote Statictest.class]
[Andy@t-ap188 row]$ java -verbose Statictest
[Loaded java.security.ProtectionDomain$Key from /usr/java/jdk1.6.0_19/jre/lib/rt.jar]
[Loaded java.security.Principal from shared objects file]
[Loaded Statictest from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
[Loaded andy.Point from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
}}}
能執行 static Point
{{{
import andy.Point;
public class Statictest {
static Point pb = new Point();
public static void main(String[] args) {
Statictest.pb.x = 6;
Statictest.pb.y = 10;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
}}}
{{{
[Andy@t-ap188 row]$ javac -verbose Statictest.java
[parsing started Statictest.java]
[parsing completed 31ms]
[search path for source files: .]
[search path for class files: /usr/java/jdk1.6.0_19/jre/lib/resources.jar,/usr/java/jdk1.6.0_19/jre/lib/rt.jar,/usr/java/jdk1.6.0_19/jre/lib/sunrsasign.jar,/usr/java/jdk1.6.0_19/jre/lib/jsse.jar,/usr/java/jdk1.6.0_19/jre/lib/jce.jar,/usr/java/jdk1.6.0_19/jre/lib/charsets.jar,/usr/java/jdk1.6.0_19/jre/classes,/usr/java/jdk1.6.0_19/jre/lib/ext/localedata.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunpkcs11.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunjce_provider.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/dnsns.jar,.]
[loading ./andy/Point.class]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking Statictest]
[wrote Statictest.class]
[Andy@t-ap188 row]$ java -verbose Statictest
[Loaded java.security.ProtectionDomain$Key from /usr/java/jdk1.6.0_19/jre/lib/rt.jar]
[Loaded java.security.Principal from shared objects file]
[Loaded Statictest from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
[Loaded andy.Point from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
}}}
Final
若將 Final class A = new ClassA()
則 classA 就被 bond 住, 不行將 classA assign 到其於 ClassA instance.
{{{
import andy.Point;
public class Finaltest {
public static void main(String[] args) {
final Point pa = new Point();
pa.x = 10;
pa.y = 11;
System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
pa.x = 15;
// Not correct
pa = new Point();
}
}}}
{{{
[Andy@t-ap188 row]$ javac Finaltest.java
Finaltest.java:12: cannot assign a value to final variable pa
pa = new Point();
^
1 error
[Andy@t-ap18
}}}
則 classA 就被 bond 住, 不行將 classA assign 到其於 ClassA instance.
{{{
import andy.Point;
public class Finaltest {
public static void main(String[] args) {
final Point pa = new Point();
pa.x = 10;
pa.y = 11;
System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
pa.x = 15;
// Not correct
pa = new Point();
}
}}}
{{{
[Andy@t-ap188 row]$ javac Finaltest.java
Finaltest.java:12: cannot assign a value to final variable pa
pa = new Point();
^
1 error
[Andy@t-ap18
}}}
Javac
. 簡單的方式, 當需要編譯的 class 都在目前目錄下
如果要編一個 java 程式, 要其它的 class, 會在目前目錄下找出 class,
如有一個 FinalTest.java 與 Point.java
1. javac -verbose FinalTest.java
[Andy@t-ap188 row]$ javac -verbose Finaltest.java
[parsing started Finaltest.java]
[parsing completed 37ms]
[search path for source files: .]
[search path for class files: /usr/java/jdk1.6.0_19/jre/lib/resources.jar,/usr/java/jdk1.6.0_19/jre/lib/rt.jar,/usr/java/jdk1.6.0_19/jre/lib/sunrsasign.jar,/usr/java/jdk1.6.0_19/jre/lib/jsse.jar,/usr/java/jdk1.6.0_19/jre/lib/jce.jar,/usr/java/jdk1.6.0_19/jre/lib/charsets.jar,/usr/java/jdk1.6.0_19/jre/classes,/usr/java/jdk1.6.0_19/jre/lib/ext/localedata.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunpkcs11.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunjce_provider.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/dnsns.jar,.]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking Finaltest]
[loading ./Point.class]
[wrote Finaltest.class]
[total 325ms]
Final.java
{{{
public class Finaltest {
public static void main(String[] args) {
Point pa = new Point();
//pa.x = 10;
//pa.y = 11;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
Point.java
{{{
public class Point {
public int x;
public int y;
}
}}}
此時 Point 還沒有作 package 所以不用 import
在 java Finaltest 時
{{{
[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
[Loaded java.lang.reflect.Type from shared objects file]
[Loaded java.lang.reflect.AnnotatedElement from shared objects file]
[Loaded java.lang.Class from shared objects file]
[Loaded java.lang.Cloneable from shared objects file]
[Loaded java.lang.ClassLoader from shared objects file]
[Loaded Finaltest from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
[Loaded Point from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/andy/]
}}}
2. 如果在編譯的檔案放在 其於目錄要用 -classpath or export CLASSPATH=""
如將 Point 移動到 ./andy
則
javac -classpath ./andy -verbose Finaltest.java
java -verbose -classpath ./:./andy Finaltest
3. 如果在 Point 使用 package 代表告訴 在哪個下的物件
則在
Point.java
{{{
package andy;
public class Point {
public int x;
public int y;
}
}}}
Finaltest
{{{
import andy.Point;
public class Finaltest {
public static void main(String[] args) {
Point pa = new Point();
//pa.x = 10;
//pa.y = 11;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
}}}
Reference:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
如果要編一個 java 程式, 要其它的 class, 會在目前目錄下找出 class,
如有一個 FinalTest.java 與 Point.java
1. javac -verbose FinalTest.java
[Andy@t-ap188 row]$ javac -verbose Finaltest.java
[parsing started Finaltest.java]
[parsing completed 37ms]
[search path for source files: .]
[search path for class files: /usr/java/jdk1.6.0_19/jre/lib/resources.jar,/usr/java/jdk1.6.0_19/jre/lib/rt.jar,/usr/java/jdk1.6.0_19/jre/lib/sunrsasign.jar,/usr/java/jdk1.6.0_19/jre/lib/jsse.jar,/usr/java/jdk1.6.0_19/jre/lib/jce.jar,/usr/java/jdk1.6.0_19/jre/lib/charsets.jar,/usr/java/jdk1.6.0_19/jre/classes,/usr/java/jdk1.6.0_19/jre/lib/ext/localedata.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunpkcs11.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/sunjce_provider.jar,/usr/java/jdk1.6.0_19/jre/lib/ext/dnsns.jar,.]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking Finaltest]
[loading ./Point.class]
[wrote Finaltest.class]
[total 325ms]
Final.java
{{{
public class Finaltest {
public static void main(String[] args) {
Point pa = new Point();
//pa.x = 10;
//pa.y = 11;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
Point.java
{{{
public class Point {
public int x;
public int y;
}
}}}
此時 Point 還沒有作 package 所以不用 import
在 java Finaltest 時
{{{
[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
[Loaded java.lang.reflect.Type from shared objects file]
[Loaded java.lang.reflect.AnnotatedElement from shared objects file]
[Loaded java.lang.Class from shared objects file]
[Loaded java.lang.Cloneable from shared objects file]
[Loaded java.lang.ClassLoader from shared objects file]
[Loaded Finaltest from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/]
[Loaded Point from file:/home/Andy/Desktop/working/JavaAll/JavaPractice/row/andy/]
}}}
2. 如果在編譯的檔案放在 其於目錄要用 -classpath or export CLASSPATH=""
如將 Point 移動到 ./andy
則
javac -classpath ./andy -verbose Finaltest.java
java -verbose -classpath ./:./andy Finaltest
3. 如果在 Point 使用 package 代表告訴 在哪個下的物件
則在
Point.java
{{{
package andy;
public class Point {
public int x;
public int y;
}
}}}
Finaltest
{{{
import andy.Point;
public class Finaltest {
public static void main(String[] args) {
Point pa = new Point();
//pa.x = 10;
//pa.y = 11;
//System.out.println("pa.x:" + pa.x + ", pa.y" + pa.y);
}
}
}}}
Reference:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
2010年4月2日 星期五
Attribute 討論
若在 JSP 中要儲存一個變數到下次還能使用可利用 setAttribute on session class,
當要取用時可用 getAttribute, 但要注意 get 時要給定型態, 否則會發生型態錯誤, 理由是 setAttribute 可能用 hash table 存 key value, 而 value 則是 primitive object.
ex.
String dmPath = "/home/Andy", dmPath2;
session.setAttribute("dmPath", dmPath);
dmPath2 = (String) session.getAttribute("dmPath");
當要取用時可用 getAttribute, 但要注意 get 時要給定型態, 否則會發生型態錯誤, 理由是 setAttribute 可能用 hash table 存 key value, 而 value 則是 primitive object.
ex.
String dmPath = "/home/Andy", dmPath2;
session.setAttribute("dmPath", dmPath);
dmPath2 = (String) session.getAttribute("dmPath");
System Properties
1. Java System properties define the system environment , They are stored by the System class in a Properties object.
2. Example System.getProperty("user.home");
Key | Description of Associated Value |
---|---|
java.version | Java Runtime Environment version |
java.vendor | Java Runtime Environment vendor |
java.vendor.url | Java vendor URL |
java.home | Java installation directory |
java.vm.specification.version | Java Virtual Machine specification version |
java.vm.specification.vendor | Java Virtual Machine specification vendor |
java.vm.specification.name | Java Virtual Machine specification name |
java.vm.version | Java Virtual Machine implementation version |
java.vm.vendor | Java Virtual Machine implementation vendor |
java.vm.name | Java Virtual Machine implementation name |
java.specification.version | Java Runtime Environment specification version |
java.specification.vendor | Java Runtime Environment specification vendor |
java.specification.name | Java Runtime Environment specification name |
java.class.version | Java class format version number |
java.class.path | Java class path |
java.library.path | List of paths to search when loading libraries |
java.io.tmpdir | Default temp file path |
java.compiler | Name of JIT compiler to use |
java.ext.dirs | Path of extension directory or directories |
os.name | Operating system name |
os.arch | Operating system architecture |
os.version | Operating system version |
file.separator | File separator ("/" on UNIX) |
path.separator | Path separator (":" on UNIX) |
line.separator | Line separator ("\n" on UNIX) |
user.name | User's account name |
user.home | User's home directory |
user.dir | User's current working directory |
2. Example System.getProperty("user.home");
The I/O package
1. java.io define I/O (input/output) in terms of stream
2. Streams are ordered sequence of data that have a source or destination
3. The java.io has two major part: character streams and bytes stream
04.01
我碰到, 可以建立 一個 byte outputstream 並將它輸出 file outputstram, 而寫法為
FileOutputStream fout = new FileOutputStream("FBJ");
bjectOutputStream oout = new ObjectOutputStream(fout);
2. Streams are ordered sequence of data that have a source or destination
3. The java.io has two major part: character streams and bytes stream
04.01
我碰到, 可以建立 一個 byte outputstream 並將它輸出 file outputstram, 而寫法為
FileOutputStream fout = new FileOutputStream("FBJ");
bjectOutputStream oout = new ObjectOutputStream(fout);
2010年4月1日 星期四
PATH 的討論
1. gap 並沒有實際的 file, 這是個方法 gap file => Path, 但java的File有太多features是我要當做一個GAP DM file所不須要的, 為了單純化,就不用它了
2.
2.
Method Summary | |
---|---|
int | compareTo(java.lang.Object o) Compare this object to another object |
boolean | equals(java.lang.Object o) Compare if this object is equal to another object |
java.lang.String | getGroup() Get the group associated with the file. |
long | getLen() |
java.sql.Timestamp | getModificationTime() Get the modification time of the file. |
java.lang.String | getOwner() Get the owner of the file. |
java.lang.String | getParentID() |
net.asgc.gap.dm.fs.Path | getPath() Get the file abosolute path |
java.lang.String | getPhysicalPath() |
java.lang.String | getSEHost() |
java.lang.String | getSEType() |
java.lang.String | getUID() |
int | hashCode() Returns a hash code value for the object, which is defined as the hash code of the path name. |
boolean | isDir() Is this a directory? |
void | setGroup(java.lang.String group) Sets group. |
void | setLen(long length) |
void | setModificationTime(java.sql.Timestamp dt) |
void | setOwner(java.lang.String owner) Sets owner. |
void | setParentID(java.lang.String pID) |
void | setPath(net.asgc.gap.dm.fs.Path p) |
void | setPhysicalPath(java.lang.String surl) |
void | setSEHost(java.lang.String sh) |
void | setSEType(java.lang.String st) |
File System Discuss
1. File system 提供方法給使用者, 隱藏了底層的 mataserver 和 driver
2. 目前方法
2. 目前方法
Method Summary | |
---|---|
void | create(java.lang.String type, java.io.File src, net.asgc.gap.dm.fs.Path destFile) Upload a local file object to GAP DM, and should assign a storage type(Driver) to upload |
java.io.OutputStream | create(java.lang.String type, net.asgc.gap.dm.fs.Path destFile) Create (Upload) a file to GAP file system |
void | create(net.asgc.gap.dm.fs.UploadBeen destFileSet) Create (upload) file list to GAP file system |
net.asgc.gap.dm.fs.driver.Driver | getDriver(java.lang.String type) Get driver by key |
net.asgc.gap.dm.fs.FileStatus | getFileStatus(net.asgc.gap.dm.fs.Path p) Get the metadata for a file |
net.asgc.gap.dm.fs.FileStatus | getTempStatus() |
net.asgc.gap.dm.fs.Path | getWorkingDir() |
net.asgc.gap.dm.fs.FileStatus[] | listStatus(net.asgc.gap.dm.fs.Path p) Get metadata of all directories and files under a directory |
static void | main(java.lang.String[] args) |
boolean | mkdirs(net.asgc.gap.dm.fs.Path f) create a directory |
java.io.InputStream | open(net.asgc.gap.dm.fs.Path srcDMPath) Open (Download) a file from GAP file system |
void | open(net.asgc.gap.dm.fs.Path srcDMPath, net.asgc.gap.dm.fs.Path dest) |
void | refreshTempStatus() |
boolean | rename(net.asgc.gap.dm.fs.Path src, net.asgc.gap.dm.fs.Path dst) |
boolean | setFileStatus(net.asgc.gap.dm.fs.Path destDMPath, net.asgc.gap.dm.fs.FileStatus status) Set(Create) the metadata for a file |
void | setWorkingDir(net.asgc.gap.dm.fs.Path workingDir) |
boolean | updateFileStatus(net.asgc.gap.dm.fs.FileStatus status) Update the metadata for a file |
容器多型宣告
1. 說明
List downloadFileList = new ArrayList();
1. 知道 List 為介面, 而 ArrayList 是實作, 不能將 List 作物化.
2. 多形要用 表示
2. 範例:
I. 寫個簡單的 arrayList 並使用 add 和 get(i), 還可以用 inner for 去得到值,
相當方便.
ListTest.java
{{{
import java.util.*;
public class ListTest {
public static void main(String[] args) {
List arrayList = new ArrayList();
arrayList.add("one");
arrayList.add("two");
for (String s : arrayList) {
System.out.println(s);
}
// System.out.println(arrayList.get(0));
// System.out.println(arrayList.get(1));
}
}
}}}
List
1. 知道 List 為介面, 而 ArrayList 是實作, 不能將 List 作物化.
2. 多形要用
2. 範例:
I. 寫個簡單的 arrayList 並使用 add 和 get(i), 還可以用 inner for 去得到值,
相當方便.
ListTest.java
{{{
import java.util.*;
public class ListTest {
public static void main(String[] args) {
List
arrayList.add("one");
arrayList.add("two");
for (String s : arrayList) {
System.out.println(s);
}
// System.out.println(arrayList.get(0));
// System.out.println(arrayList.get(1));
}
}
}}}
訂閱:
文章 (Atom)