• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Java的一些类的使用经验

servlet/jsp 搞代码 7年前 (2018-06-18) 123次浏览 已收录 0个评论

 

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类中,在静态法方法中,不能使用类的属性变量!

http://www.gaodaima.com/40477.htmlJava的一些类的使用经验

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.

欢迎大家阅读《Java的一些类的使用经验》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Java的一些类的使用经验
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址