File[] acceptedFiles= new File[files.length];
int pos = 0;
for(File file:files){
booleanaccepted = filter.accept(file);
if(accepted){
//acceptedFilesList.add(file);
acceptedFiles[pos++]= file;
}
}
Arrays.copyOf(acceptedFiles,pos);
//return(File[])accpetedFilesList.toArray();
}
¡¡¡¡3¡¢±àдһ¸ö½ØÈ¡×Ö·û´®µÄº¯Êý£¬ÊäÈëΪһ¸ö×Ö·û´®ºÍ×Ö½ÚÊý£¬Êä³öΪ°´×Ö½Ú½ØÈ¡µÄ×Ö·û´®£¬µ«Òª±£Ö¤ºº×Ö²»±»½ØÈ¡°ë¸ö£¬Èç¡°ÎÒABC¡±£¬4£¬Ó¦¸Ã½ØÈ¡¡°ÎÒAB¡±£¬ÊäÈë¡°ÎÒABCººDEF¡±£¬6£¬Ó¦¸ÃÊä³ö¡°ÎÒABC¡±£¬¶ø²»ÊÇ¡°ÎÒABC+ººµÄ°ë¸ö¡±¡£
´ð£º
Ê×ÏÈÒªÁ˽âÖÐÎÄ×Ö·ûÓжàÖÖ±àÂë¼°¸÷ÖÖ±àÂëµÄÌØÕ÷¡£
¼ÙÉènΪҪ½ØÈ¡µÄ×Ö½ÚÊý¡£
public static voidmain(String[] args) throws Exception{
String str ="ÎÒa°®ÖлªabcÎÒ°®´«ÖÇdef';
String str ="ÎÒABCºº";
int num =trimGBK(str.getBytes("GBK"),5);
System.out.println(str.substring(0,num));
}
public staticint trimGBK(byte[] buf,int n){
int num = 0;
booleanbChineseFirstHalf = false;
for(inti=0;i
{
if(buf[i]<0&& !bChineseFirstHalf){
bChineseFirstHalf= true;
}else{
num++;
bChineseFirstHalf= false;
}
}
return num;
}
¡¡¡¡4¡¢ÓÐÒ»¸ö×Ö·û´®£¬ÆäÖаüº¬ÖÐÎÄ×Ö·û¡¢Ó¢ÎÄ×Ö·ûºÍÊý×Ö×Ö·û£¬Çëͳ¼ÆºÍ´òÓ¡³ö¸÷¸ö×Ö·ûµÄ¸öÊý¡£
´ð£º¹þ¹þ£¬Æäʵ°üº¬ÖÐÎÄ×Ö·û¡¢Ó¢ÎÄ×Ö·û¡¢Êý×Ö×Ö·ûÔÀ´ÊdzöÌâÕ߷ŵÄÑÌÎíµ¯¡£
String content = ¡°ÖйúaadfµÄ111Èøbbb·ÆµÄzzÈø·Æ¡±;
HashMap map = new HashMap();
for(int i=0;i
{
char c =content.charAt(i);
Integer num =map.get(c);
if(num == null)
num = 1;
else
num = num +1;
map.put(c,num);
}
for(Map.EntrySet entry : map)
{
system.out.println(entry.getkey()+ ¡°:¡± + entry.getValue());
}
¹À¼ÆÊǵ±³õÃæÊÔµÄÄǸöѧԱ±íÊö²»Çå³þ£¬ÎÊÌâºÜ¿ÉÄÜÊÇ£º
Èç¹ûÒ»´®×Ö·ûÈç"aaaabbcÖйú1512"Òª·Ö±ðͳ¼ÆÓ¢ÎÄ×Ö·ûµÄÊýÁ¿£¬ÖÐÎÄ×Ö·ûµÄÊýÁ¿£¬ºÍÊý×Ö×Ö·ûµÄÊýÁ¿£¬¼ÙÉè×Ö·ûÖÐûÓÐÖÐÎÄ×Ö·û¡¢Ó¢ÎÄ×Ö·û¡¢Êý×Ö×Ö·ûÖ®ÍâµÄÆäËûÌØÊâ×Ö·û¡£
int engishCount;
int chineseCount;
int digitCount;
for(int i=0;i
{
charch = str.charAt(i);
if(ch>=¡¯0¡¯&& ch<=¡¯9¡¯)
{
digitCount++
}
elseif((ch>=¡¯a¡¯&& ch<=¡¯z¡¯) || (ch>=¡¯A¡¯ && ch<=¡¯Z¡¯))
{
engishCount++;
}
else
{
chineseCount++;
}
}
System.out.println(¡¡¡¡¡);
¡¡¡¡5¡¢ËµÃ÷Éú»îÖÐÓöµ½µÄ¶þ²æÊ÷£¬ÓÃjavaʵÏÖ¶þ²æÊ÷
ÕâÊÇ×éºÏÉè¼ÆÄ£Ê½¡£
ÎÒÓкܶà¸ö(¼ÙÉè10Íò¸ö)Êý¾ÝÒª±£´æÆðÀ´£¬ÒÔºó»¹ÐèÒª´Ó±£´æµÄÕâЩÊý¾ÝÖмìË÷ÊÇ·ñ´æÔÚij¸öÊý¾Ý£¬£¨ÎÒÏë˵³ö¶þ²æÊ÷µÄºÃ´¦£¬¸ÃÔõÃ´ËµÄØ£¿ÄǾÍÊÇ˵±ðÈ˵Äȱµã£©£¬¼ÙÈç´æÔÚÊý×éÖУ¬ÄÇô£¬ÅöÇÉÒªÕÒµÄÊý×ÖλÓÚ99999ÄǸöµØ·½£¬ÄDzéÕÒµÄËٶȽ«ºÜÂý£¬ÒòΪҪ´ÓµÚ1¸öÒÀ´ÎÍùºóÈ¡£¬È¡³öÀ´ºó½øÐбȽϡ£Æ½ºâ¶þ²æÊ÷£¨¹¹½¨Æ½ºâ¶þ²æÊ÷ÐèÒªÏÈÅÅÐò£¬ÎÒÃÇÕâÀï¾Í²»×÷¿¼ÂÇÁË£©¿ÉÒԺܺõؽâ¾öÕâ¸öÎÊÌ⣬µ«¶þ²æÊ÷µÄ±éÀú£¨Ç°Ðò£¬ÖÐÐò£¬ºóÐò£©Ð§ÂÊÒª±ÈÊý×éµÍºÜ¶à£¬ÔÀíÈçÏÂͼ£º
´úÂëÈçÏ£º
package com.huawei.interview;
publicclass Node {
public int value;
public Node left;
public Node right;
public void store(intvalue)
{
if(value<this.value)
{
if(left ==null)
{
left = new Node();
left.value=value;
}
else
{
left.store(value);
}
}
else if(value>this.value)
{
if(right ==null)
{
right = new Node();
right.value=value;
}
else
{
right.store(value);
}
}
}
public boolean find(intvalue)
{
System.out.println("happen" +this.value);
if(value ==this.value)
{
return true;
}
else if(value>this.value)
{
if(right ==null)returnfalse;
return right.find(value);
}else
{
if(left ==null)returnfalse;
return left.find(value);
}
}
public void preList()
{
System.out.print(this.value+ ",");
if(left!=null)left.preList();
if(right!=null) right.preList();
}
public void middleList()
{
if(left!=null)left.preList();
System.out.print(this.value+ ",");
if(right!=null)right.preList();
}
public void afterList()
{
if(left!=null)left.preList();
if(right!=null)right.preList();
System.out.print(this.value+ ",");
}
public static voidmain(String [] args)
{
int [] data =new int[20];
for(inti=0;i
{
data[i] = (int)(Math.random()*100)+ 1;
System.out.print(data[i] +",");
}
System.out.println();
Node root = new Node();
root.value = data[0];
for(inti=1;i
{
root.store(data[i]);
}