參加7k7k筆試,遇到這樣一個選擇題,主要考String字串、equals()、==的結合。 public class Demo { public static void main(String args[]) { String str=new String("hello"); if(str=="hello")
今天去博彥參加筆試,有一個演算法,分享一下。 建立一個int類型的數組,隨機給其賦值1-100內的數,且數組元素不能重複。 java實現: public class demo01 { public static void main(String args[]){ int A[]=new int[100]; for(int i=0;i<100;i++) { A[i]=i+1; }
主要考static、局部變數、執行個體變數的相關知識結合。 public class Demo{ static String str[]=new String[5]; public static void main(String args[]){ System.out.println(str[1]); }
ApacheNutch顯示網頁快照時,如果有漢字,可能會出現亂碼。比如,原網頁是用gb2312編碼的,顯示時就不能正常顯示。解決方案是:當不能正常取到Encoding時,就從Content-Type中擷取。具體為:修改cached.jsp檔案把 else content = new String(bean.getContent(details));修改為: else { int index = contentType.indexOf("charset=");
最有效方法是:public class Demo02 { public static void main(String args[]){ int a=2<<3; System.out.println(a); }} 解析: a << b就表示把a轉為二進位後左移b位(在後面添b個0)。例如100的二進位為1100100,而110010000轉成十進位是4
使用冒泡排序法現在可以使用對數組進行排序,但是有些複雜。通過Arrays類的靜態sort()方法可實現對數組排序,sort()方法提供了許多重載形式,可對任意類型的數組進行升序排序。package Java.programming;import java.util.Arrays;//通過Arrays類的靜態sort()方法實現對數組排序,sort()方法提供了許多種重載形式,可對任意類型的數組進行升序排序public class SortArr { public static
Collection、Map主要用於盛裝其他對象,而Iterator則主要用於遍曆Collection集合中的元素,Iterator對象也被稱為迭代器。 例如: public class IteratorTest { public static void main(String args[]) { Collection books=new HashSet();