111111
精灵王
精灵王
  • 注册日期2010-12-08
  • 发帖数640
  • QQ
  • 火币1103枚
  • 粉丝120
  • 关注75
  • 社区明星
阅读:3090回复:0

Java的一些类的使用经验-JSP教程,Java技巧及代码

楼主#
更多 发布于:2010-12-15 13:11
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.



喜欢0 评分0
游客

返回顶部