1.對字串的末尾的進行限定的方法(例:讓末尾不含,—,,)
while(strTrue.endsWith("+")||strTrue.endsWith("-")||strTrue.endsWith(","))//過濾掉末尾的++號
strTrue=strTrue.substring(0,strTrue.length()-1);
2.一定要記住:對於數字要用==來比較,對於字串則要用.equals(String)來比較,否則對於==的比較始終為否。
3.String 類型安標準來說沒有長度限制,但是一般jdk中String的最大長度是4G
5.對於在java類中,在靜態法方法中,不能使用類的屬性變數。
6.對於Iterator 介面
Collection 介面的iterator()方法返回一個 Iterator。Iterator介面方法能以迭代方式逐個訪問集合中各個元素,並安全的從Collection 中除去適當的元素。
(1) boolean hasNext(): 判斷是否存在另一個可訪問的元素
Object next(): 返回要訪問的下一個元素。如果到達集合結尾,則拋出NoSuchElementException異常。
(2) void remove(): 刪除上次訪問返回的對象。本方法必須緊跟在一個元素的訪問後執行。如果上次訪問後集合已被修改,方法將拋出IllegalStateException。Iterator中刪除操作對底層Collection也有影響。
即在一個hasNext()下,不要多次的調用.next()方法,否則會出現:NoSuchElementException異常。
7.對於把字串轉成Integer類型時,對於一般的不要用Integer.getInteger("23"),它可能轉成一個null,因此是先把它轉成用Integer.ParseInt轉成int,然後強制類型轉換:new Integer(23)即。 8.顯示一個yyyy-mm-dd hh:mm的時間
import java.util.*;
public class test{
public static void main(String srt[])
{
Date d=new Date();
GregorianCalendar z=new GregorianCalendar();
z.setTime(d);
String dateTime=z.get(Calendar.YEAR)+"-"+z.get(Calendar.MONTH)+"-"+z.get(Calendar.DAY_OF_MONTH)+" "+z.get(Calendar.HOUR)+":"+z.get(Calendar.MINUTE);
System.out.println(dateTime);
System.out.println(d.toString());
}
} 9.對於double和float型的數取得加號或減號的辦法:
math.sinnum(..);
下面有來自類庫的資訊
Class Math
java.lang.Object
java.lang.Math
其中有有關加號或減號方法如下可以解決你的問題
static double signum(double d)
Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.
static float signum(float f)
Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.