0
A
回答
1
,你可以這樣做:
public static void main(String[] args) {
String s="ab [email protected]#$&*()//CcAB897987";
List upperChar=new ArrayList();
String a = s.replaceAll("[^A-Z\\-]", ""); // remove all character other Uppercase character
char []ch=a.toCharArray(); // this contains all uppercase character
for (int i = 0; i < ch.length; i++) {
upperChar.add(ch[i]); // make a list of uppercase char.
}
System.out.println(upperChar);
}
輸出:
[C, A, B]
1
Rmove所有非大寫字母,然後轉換成字符數組。
String str = "abCcAB";
String a = str.replaceAll("[^A-Z]", "");
System.out.println(a.toCharArray());
0
psedocode:
queue output; //declaration of the character array for output
while(input.length!=0){ //checking the length of the input array
firstcharacter=string.charAt(0); //getting the firstCharacter of the input string
if(character.IsUpperCase(firtcharacter)){ //checking if the firstCharacter is uppercase
output.enqueue(firtcharacter); //if the character is uppercase add to the array
}
input=input.substring(1,string.length); //remove the first character from the string
}
//output should now contain all the uppercase characters.
這背後是解決問題的邏輯。
0
試試這個:
public class CaptialChars {
public static void main(String[] args){
String input="SaGaR";
char[] output=input.replaceAll("[a-z]", "").toCharArray();
for(char character:output){
System.out.println(character);
}
}
}
相關問題
- 1. SQL Server,將字母數字字符串轉換爲大寫字母數字
- 2. 在php中將俄文字符從大寫字母轉換爲小寫字母
- 3. 帶大寫字母和小寫字母的字符串轉換
- 4. 將包含大寫字母的字符串轉換爲小寫字母
- 5. 將大寫字母轉換爲小寫字母,反之亦然字符串
- 6. 將字符串變量轉換爲大寫字母php
- 7. 將字符串轉換爲大寫字母有問題
- 8. 將字符串轉換爲所有大寫字母與std :: transform
- 9. 將字符串轉換爲大寫字母,不屬於任何特殊字符
- 10. Java如何將小寫字符串值轉換爲字符串數組中的大寫字符串
- 11. 將字符串轉換爲字節數組並將字節數組轉換爲字符串
- 12. 將字符串中特定字符轉換爲大寫
- 13. mySQL將字符串中的字符轉換爲大寫
- 14. 將jlist選擇轉換爲字符串
- 15. C#將字節數組與字符串轉換爲字符串
- 16. 將字典<字符串,字符串>轉換爲數組
- 17. 將所有大寫字母替換爲小寫字母,除了urlencoded字符串
- 18. 將字符串數組轉換爲字節數組並返回
- 19. 如何將字符串中的字母轉換爲數字 - C++
- 20. 將字符串轉換爲Java中的字符串數組
- 21. 將字符串數組轉換爲VBA中的新字符串
- 22. 將字符串的替代字符轉換爲大寫。字符串的第一個字母必須是Capital
- 23. Java:如何將字母數字字符串轉換爲整數並從整數轉換爲相同的字母數字字符串?
- 24. 將字符串數組字符轉換爲數字
- 25. 將字母數字字符串轉換爲整數格式
- 26. 將字符串(字母)從文本文本轉換爲整數
- 27. 在C++中將字符數組轉換爲整數字符串
- 28. 如何將一個字符串轉換爲一個字符數組中的字符大小的字符數組?
- 29. 如何將小寫字符串轉換爲大寫字母,反之亦然?
- 30. 我需要字符串轉換JSP中成首字母大寫
你可以張貼一些代碼,你試過嗎? – Ajit 2014-11-04 08:48:53
先刪除小寫字母(例如使用正則表達式),然後使用toCharArray()。 – sp00m 2014-11-04 08:51:02
投票結束,因爲OPs缺乏努力。 – 2014-11-04 08:52:09