[英]How do i print one element of an arraylist to uppurcase while the other elements lowercase
the elements of array list need to be printed one by one, which one be printed uppsercase other lowercase数组列表的元素需要一一打印,哪一个大写,哪一个小写
public static void main(String[] args) {
String[] days = {"monday","saturday","tuesday","sunday","friday"};
ArrayList<String> weekdays = new ArrayList();
weekdays.add("monday");
weekdays.add("thursday");
weekdays.add("wednesday");
weekdays.add("surtaday");
weekdays.add("tuesday");
weekdays.add("sunday");
weekdays.add("friday");
// Loop through the ArrayList, printing out "sunday" elements in
for(int i=0;i<weekdays.size();i++){
System.out.println(weekdays.get(i));
}
}
Can you not add the word to the list as an uppercase letter?您不能将单词作为大写字母添加到列表中吗? If not, depending on which word you want to capitalize, i'm assuming the first one, you can do this:如果没有,根据您要大写的单词,我假设是第一个,您可以这样做:
for(int i=0;i<weekdays.size();i++){
if(i == 0){
System.out.println(weekdays.get(i).toUpperCase());
}else{
System.out.println(weekdays.get(i));
}
}
Similarily, if you want to do the second word:同样,如果你想做第二个词:
for(int i=0;i<weekdays.size();i++){
if(i == 1){ //change this from 0 to 1
System.out.println(weekdays.get(i).toUpperCase());
}else{
System.out.println(weekdays.get(i));
}
}
and so on... You need to change the value in the if statement depending on the word you want to capitalize等等...您需要根据要大写的单词更改 if 语句中的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.