Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (String s : arrayListWords) {
- System.out.print(s + ", ");
- }
- if (arrayListWords.length >= 1) {
- System.out.print(arrayListWords[0];
- }
- // note that i starts at 1, since we already printed the element at index 0
- for (int i = 1; i < arrayListWords.length, i++) {
- System.out.print(", " + arrayListWords[i]);
- }
- // assume String
- Iterator<String> it = arrayListWords.iterator();
- if (it.hasNext()) {
- System.out.print(it.next());
- }
- while (it.hasNext()) {
- System.out.print(", " + it.next());
- }
- public static void main(String[] args) throws Exception {
- final List<String> words = Arrays.asList(new String[]{"one", "two", "three", "four"});
- final Iterator<String> wordIter = words.iterator();
- final StringBuilder out = new StringBuilder();
- while (wordIter.hasNext()) {
- out.append(wordIter.next());
- if (wordIter.hasNext()) {
- out.append(",");
- }
- }
- System.out.println(out.toString());
- }
- public static void main(String[] args) throws Exception {
- final List<String> words = Arrays.asList(new String[]{"one", "two", "three", "four"});
- System.out.println(Joiner.on(",").join(words));
- }
- List<String> listWords= Arrays.asList(arrayListWords); // convert array to List
- StringBuilder sb=new StringBuilder();
- sb.append(listWords);
- System.out.println(sb.toString().replaceAll("\[|\]",""));
- StringBuilder res = new StringBuilder();
- for (String s : arrayListWords) {
- res.append(s).append(", ");
- }
- System.out.println(res.deleteCharAt(res.length()-2).toString());
- String str = java.util.Arrays.toString(arrayListWords);
- str = str.substring(1,str.length()-1);
- System.out.println(str);
- String s = arrayListWords.toString();
- System.out.println(s);
- //This will print it like this: "[one, two, three, four]"
- //If you want to remove the brackets you can do so easily. Just change the way you print.
- String s=arrayListWords.toString();
- System.out.print(s.substring(1, s.length()-1));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement