2013年1月4日 星期五

Java 字串 String API 用法大全

0

Java 字串 String API 用法大全  String是一個比較特別的資料型態,它是一個物件類別( Object ),基本型態所對應的物件類別,可直接給於相同類型的值,而不需使用new來產生物件,而String資料型態跟基本型態一樣可以直接給於值,不過String沒有相對應的基本型態。 String在使用上十分普遍,大部份的資料型能都可以變成String存放。String本身是字串是使用utf8格式存放的,所以在計算字元時,一個中文字跟一個英文字都是算1,這點是跟其它程式語言不太一樣的。  String的宣告及初始化 “ ”雙引號內資料則為String資料型能 # //直接給值 String a = "123"; System.out.println("a:"+a); //new 一個String物件 String b = new String("456"); System.out.println("b:"+b); //先宣告再給值 String c ; c = "789"; System.out.println("c:"+c); //先宣告再new一個物件 String d; d = new String("321"); System.out.println("d:"+d); 字串的連結合併 字串的連結合併是利用 + 來使二個字串變成一個字串 # String z = a +...

2012年12月17日 星期一

JSP裡的變量列表

0

JSP裡的變量列表 <% out.println("Protocol: " + request.getProtocol() + " "); out.println("Scheme: " + request.getScheme() + " "); out.println("Server Name: " + request.getServerName() + " " ); out.println("Server Port: " + request.getServerPort() + " "); out.println("Protocol: " + request.getProtocol() + " "); out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo() + " "); out.println("Remote Addr: " + request.getRemoteAddr() + " "); out.println("Remote Host: " + request.getRemoteHost() + " "); out.println("Character Encoding: " + request.getCharacterEncoding() + " "); out.println("Content Length: " + request.getContentLength() + " "); out.println("Content Type: "+ request.getContentType() + " "); out.println("Auth Type: " + request.getAuthType() + " ");...

2012年12月14日 星期五

JSP Page 指令

0

JSP Page 指令 內容、字碼設定 <%@ page contentType="text/html;charset=big5" %> 引入套件 <%@ page import="java.util.*" %> 指定錯誤處理頁面 <%@ page errorPage="error.jsp" %> 定義這個網頁是錯誤處理頁面 <%@ page isErrorPage="true" %> 網頁編碼的指定 <%@ page pageEncoding="big5" %> ...

2012年12月12日 星期三

Vector Example in java

0

In this example we are going to show the use of java.util.Vector class. We will be creating an object of Vector class and performs various operation like adding, removing etc. Vector class extends AbstractList and implements List, RandomAccess, Cloneable, Serializable. The size of a vector increase and decrease according to the program. Vector is synchronized. In this example we are using seven methods of a Vector class. add(Object o): It adds the element in the end of the Vector size(): It gives the number of element in the vector. elementAt(int index): It returns the element at the specified index. firstElement(): It returns the first element of the vector. lastElement(): It returns last element. removeElementAt(int index): It deletes the element from the given index. elements():...