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.

|