Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÖÐÔõÑùÅжÏÒ»¸ö×Ö·û´®ÊÇ·ñÊÇÊý×Ö???

 ÔÚ±à³ÌµÄʱºò£¬¾­³£Óöµ½ÒªÅжÏÒ»¸ö×Ö·û´®ÖеÄ×Ö·ûÊÇ·ñÊÇÊý×Ö(0-9)
 ÏÂÃæÎÒ¸ø´ó¼Ò½éÉܼ¸ÖÖʵÏÖ·½·¨
1.ʹÓÃCharacter.isDigit(char)ÅжÏ
String str = "123abc";
if (!"".equals(str)) {
char num[] = str.toCharArray();//°Ñ×Ö·û´®×ª»»Îª×Ö·ûÊý×é
StringBuffer title = new StringBuffer();//ʹÓÃStringBufferÀ࣬°Ñ·ÇÊý×ַŵ½titleÖÐ
StringBuffer hire = new StringBuffer();//°ÑÊý×ַŵ½hireÖÐ
for (int i = 0; i < num.length; i++) {
// ÅжÏÊäÈëµÄÊý×ÖÊÇ·ñΪÊý×Ö»¹ÊÇ×Ö·û
if (Character.isDigit(num[i])) {°Ñ×Ö·û´®×ª»»Îª×Ö·û£¬ÔÙµ÷ÓÃCharacter.isDigit(char)·½·¨ÅжÏÊÇ·ñÊÇÊý×Ö£¬ÊÇ·µ»ØTrue£¬·ñÔòFalse
hire.append(num[i]);// Èç¹ûÊäÈëµÄÊÇÊý×Ö£¬°ÑËü¸³¸øhire
} else {
title.append(num[i]);// Èç¹ûÊäÈëµÄÊÇ×Ö·û£¬°ÑËü¸³¸øtitle
}
}
}

2.ʹÓÃÀàÐÍת»»ÅжÏ
try {
String str="123abc";
int num=Integer.valueOf(str);//°Ñ×Ö·û´®Ç¿ÖÆת»»ÎªÊý×Ö
return true;//Èç¹ûÊÇÊý×Ö£¬·µ»ØTrue
} catch (Exception e) {
return false;//Èç¹ûÅ׳öÒì³££¬·µ»ØFalse
}
3.ʹÓÃÕýÔò±í´ïʽÅжÏ
String str = "";
boolean isNum = str.matches("[0-9]+");
//+±íʾ1¸ö»ò¶à¸ö£¨Èç"3"»ò"225"£©£¬*±íʾ0¸ö»ò¶à¸ö£¨[0-9]*£©£¨Èç""»ò"1"»ò"22"£©£¬?±íʾ0¸ö»ò1¸ö([0-9]?)(Èç""»ò"7")
4.ʹÓÃPatternÀàºÍMatcher
String str = "123";
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str);
boolean result = matcher.matches();
if (result) {
System.out.println("true");
} else {
System.out.println("false");
}


Ïà¹ØÎĵµ£º

Java NIO APIÏê½â

 
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......

JAVA±ÊÊÔÌâ

µÚÒ»£º
1.StringÊÇ×î»ù±¾µÄÊý¾ÝÀàÐÍô£¿
´ð£º²»ÊÇ¡£»ù±¾µÄÊý¾ÝÀàÐÍ°üÀ¨£ºbyte,int,char,long,float,double,booleanºÍshort.
java.lang.StringÀàÊÇfinalÀàÐ͵ģ¬Òò´Ë²»¿ÉÒԼ̳ÐÕâ¸öÀ࣬²»ÄÜÐÞ¸ÄÕâ¸öÀà¡£
2.¾²Ì¬±äÁ¿ºÍʵÀý±äÁ¿µÄÇø±ð£¿
´ð£ºstatic i = 10 ;//³£Á¿  
      &nb ......

JAVA±ÊÊÔÌâÑ¡ÔñÌâ

1ÏÂÃæÄĸöÊÇÕýÈ·µÄÀàÉùÃ÷£¿¼ÙÉèÿһ¶ÎÎı¾¶¼×öΪһ¸öÃû³ÆΪFred.javaµÄÎļþµÄÈ«²¿ÄÚÈÝ£¿ a
a).
public class Fred{
public int x = 0;
public Fred (int x){
      this.x=x;
}
}
b).
public class fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
c).
public class ......

JavaÐÂÊÖÈëÃźÜÖØÒªµÄ¼¸¸ö»ù±¾¸ÅÄî

 finalÀࣺΪ·ÀÖ¹ËûÈË´ÓÄãµÄÀàÉÏÅÉÉúÐÂÀ࣬´ËÀàÊDz»¿ÉÀ©Õ¹µÄ¡£
¡¡¡¡¶¯Ì¬µ÷ÓñȾ²Ì¬µ÷Óû¨·ÑµÄʱ¼äÒª³¤¡£
¡¡¡¡³éÏóÀࣺ¹æ¶¨Ò»¸ö»ò¶à¸ö³éÏó·½·¨µÄÀà±¾Éí±ØÐ붨ÒåΪabstract¡£
¡¡¡¡Àý£º public abstract string getDescripition
¡¡¡¡JavaÖеÄÿһ¸öÀ඼ÊÇ´ÓObjectÀàÀ©Õ¹¶øÀ´µÄ¡£
¡¡¡¡objectÀàÖеÄequalºÍtoString·½· ......

Java¼¯ºÏÀàList/Set/MapµÄÇø±ðºÍÁªÏµ

 
Ò»¡¢Array £¬ Arrays
JavaËùÓГ´æ´¢¼°Ëæ»ú·ÃÎÊÒ»Á¬´®¶ÔÏó”µÄ×ö·¨£¬arrayÊÇ×îÓÐЧÂʵÄÒ»ÖÖ¡£
1¡¢
ЧÂʸߣ¬µ«ÈÝÁ¿¹Ì¶¨ÇÒÎÞ·¨¶¯Ì¬¸Ä±ä¡£
array»¹ÓÐÒ»¸öȱµãÊÇ£¬ÎÞ·¨ÅжÏÆäÖÐʵ¼Ê´æÓжàÉÙÔªËØ£¬lengthÖ»ÊǸæËßÎÒÃÇarrayµÄÈÝÁ¿¡£
2¡¢JavaÖÐÓÐÒ»¸öArraysÀ࣬רÃÅÓÃÀ´²Ù×÷array¡£
   
a ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ