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Ïê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
SetºÍÊýѧÖеļ¯ºÏÊÇͬһ¸ö¸ÅÄ¾ÍÊÇûÓÐÖظ´ÔªËصļ¯ºÏ¡£
ÕâƪÎÄÕÂÖ÷ÒªÂÛÊöÁËSetÊÇÈçºÎʵÏÖ"ûÓÐÖظ´ÔªËØ"£¨no duplicate elements£©µÄ£¬ÒÔ¼°²ûÊöÁËʲôÊÇ“Öظ´”£¨duplicate£©£¬ÊÇÏàͬµÄµØÖ·¿Õ¼ä£¿ÊÇequalsµÄ·µ»ØֵΪtrue£¿ÊÇcompareToµÄ·µ»ØֵΪ0 £¿»¹ÊÇÓÐÏàͬµÄhashCode£¿±¾ÎÄ»¹¸ø³öÁËÔÚʲôÇé¿öÏÂʹÓÃʲà ......
package barchartdemo1;
import java.awt.Font;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.Numbe ......
ÊìϤC++µÄÈ˶ÔÓÚÁ½¸ö×Ö·û´®±È½ÏµÄ´úÂëÒ»¶¨ºÜÁ˽⣺
(string1==string2)
µ«ÔÚjavaÖУ¬Õâ¸ö´úÂ뼴ʹÔÚÁ½¸ö×Ö·û´®ÍêÈ«ÏàͬµÄÇé¿öÏÂÒ²»á·µ»Øfalse
JavaÖбØÐëʹÓÃstring1.equals(string2)À´½øÐÐÅжÏ
²¹³ä
Èç¹û£º
string s1=new String("Hello");
string s2=new String("Hello");
Ôò(s1==s2)=false
Èç¹û ......
µ¥Àýģʽ£¬¹ËÃû˼Ò壬ֻÄÜÓÐÒ»¸öʵÀý¡£
Ò».´Ó¶àḬ̈߳²È«ËµÆð£¬ÈçÏÂͼ´úÂ룬´ËÎÊÌâ¿ÉÒÔÓÃsynchronized¹Ø¼ü×ÖÀ´½â¾ö¡£¸Ã·½·¨È±µã£ºÃ¿Ò»¸öÏß³ÌÔÚ»ñȡʵÀý¶ÔÏó֮ǰ¶¼ÒªÔÚsynchronizedÉÏͬ²½µÄ¶ÔÏóÉϽøÐеȴý£¬Òò´ËЧÂʲ»¸ß¡£
¶þ.Double Check·½·¨£¬¼ûÏÂͼ´úÂë¡£Double CheckµÄ³õÖÔÊÇÖ»Óе±instanceΪNULLʱִÐеÄÏ̲߳ÅÐèÒªÔÚ ......