2014-02-26 28 views
0
ArrayList<String> entries = new ArrayList<String>(); 
entries.add(visits); 
System.out.println(visits); 

列表的輸出如下[wt45,wt45,wt45,88ty,de66,wt45,wt45,wt45]。現在我需要在文本文件中分離和寫入數字,任何人都可以向我建議如何做到這一點?我正在做所有這些workin jsp頁面。我想從列表中分離數字和字符,並將數字寫入文本文件

文本文件應該是這樣的:

45 
45 
45 
88 
66 
45 
45 
45 
+1

請仔細閱讀[問]。我們可以提供幫助,但我們不在這裏爲您編寫代碼。 –

+0

看看ascii碼 – developerwjk

+0

我已經搜索了問題,但沒有發現類似的問題,我問。 – Kiran

回答

0

試試吧,把你的JSP與例如,下面的代碼,希望可以幫助

public static void main(String[] args) { 
     String[] visits = {"wt45", "wt45", "wt45", "88ty", "de66", "wt45", "wt45", "wt45"}; 
     ArrayList<String> entries = new ArrayList<String>(); 
     for (String s : visits) { 
      String result = new String(); 
      for (int j = 0; j < s.length(); j++) { 
       Character chars = s.charAt(j); 
       if (Character.isDigit(chars)) { 
        result += chars; 
       } 
      } 
      entries.add(result); 
      System.out.println(result); 
     } 
    } 
+0

如果實際上只有兩位數字,那麼在這種情況下它並不重要,但是您通常不應該在循環中進行字符串連接。改用'StringBuilder'。 –

相關問題