Java tutorial
//package com.java2s; import java.util.List; public class Main { public static String getDistanceString(List<String> list) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("&origin=").append(list.get(0)); stringBuilder.append("&destination=").append(list.get(list.size() - 1)); stringBuilder.append("&waypoints="); for (int i = 1; i < list.size() - 1; i++) { stringBuilder.append(list.get(i)); if (i != list.size() - 2) stringBuilder.append("|"); } return stringBuilder.toString(); } }