import java.util.ArrayList;
public class List {
public static void main (String[] args) {
ArrayList<String> companies = new ArrayList<>();
companies.add("DELL");
companies.add("APPLE");
companies.add("SAMSUNG");
companies.add("SONY");
companies.add("ALCATEL");
for (int i = 0; i < companies.size(); i++) {
System.out.print(companies.get(i)+ ", " );
}
}
}
I want to delete last , from list
output should be :
DELL, APPLE, SAMSUNG, SONY, ALCATEL
not :
DELL, APPLE, SAMSUNG, SONY, ALCATEL, How to delete last , ?
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa L
30 May 2022, 19:44
0
Karol Grzeszczak
30 May 2022, 20:26
i get 5 times
a b c d e
a b c d e
...
0
Lisa L
30 May 2022, 21:55
??
0
Karol Grzeszczak
31 May 2022, 04:17
I was told to use a loop
i know using System.out.print(comanies); the effect is as it should be
0
Lisa L
31 May 2022, 06:46
There are various approches to output a list with a delimiter using a loop... eg.:
0
Karol Grzeszczak
31 May 2022, 07:20
Thanks a lot 😊
0