不管採用什麼方式,使用者輸入的資料都是以字串的形式存在,但是在處理的過程中可能需要把輸入資訊作為數字或者字元來使用,另外不管資訊以什麼方式儲存,最終都必須以字串的形式展示給使用者,所以需要各種資料類型與字串類型之間的轉換。首先,基礎資料型別 (Elementary Data Type)與String類型對象之間的轉換:從字串轉換成其他類型: //字串與其基礎資料型別 (Elementary Data Type)之間的轉換,以int為代表 //下面的代碼把字串轉換成數字
public class BirthDate { /** * private int day; private int month; public int year; public int getDay() * { return day; } public void setDay(int day) { this.day = day; } public * int getMonth() { return month; } public void setMonth(int month) {
在www.json.org上公布了很多Java下的json解析工具,其中org.json和json-lib比較簡單,兩者使用上差不多。下面兩段原始碼是分別使用這兩個工具解析和構造JSON的示範程式。這是使用json-lib的程式:import java.util.HashMap;import java.util.Map;import net.sf.json.JSONObject;public class Test { public static void main(String[]
Installing Java6 JDK on Ubuntu 11.10ubuntu11.10安裝java JDK6.0Since sun-java6-jdk has been removed from the default Ubuntu 11.10 (Oneiric Ocelot) repositories you need to add a PPA repository (unless you want to install by
JDK的源碼,看看到Integer.ValueOf(int)裡面做了什麼最佳化: public static Integer valueOf(int i) { final int offset = 128; if (i >= -128 && i <= 127) { // must cache return IntegerCache.cache[i + offset]; } return new Integer(i);} private static
1.出現java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver 這個錯誤:最後的原因可能如下:1.未安裝SQL Server 2000 Driver for JDBC2.安裝後還注意你程式中類所在包是否匯入了 SQL Server 2000 Driver for JDBC程式安裝後lib檔案下的三個檔案:c:/program files/Microsoft SQL Server 2000