如何为列表中的每个字符串添加或插入'(单引号),其中使用Java用逗号分隔字符串 [英] How to add or insert ' (single quotes) for every string in a list in which strings are separated by commas using Java

查看:1508
本文介绍了如何为列表中的每个字符串添加或插入'(单引号),其中使用Java用逗号分隔字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下列表

[url1,url2,url3,url4] 

此列表将基于HTML下拉列表中的多项选择.因此列表大小,即列表元素是动态变化的.我的问题是我无法获得为字符串加上单引号的逻辑. 我希望上面的字符串列表显示为

This list will be based on multiple selection from drop down list of HTML. So list size i.e., list elements change dynamically. My problem is I am unable to get the logic for getting single quotes to the strings. I want the above string list to be displayed as

'url1','url2','url3','url4' 

即每个字符串的单引号(')和逗号(,)都不应消除.请帮助我如何使用Java实现此功能.

That is single quotes (') for each string and commas (,) should not be eliminated. Please help me how to achieve this using Java.

推荐答案

  1. 迭代列表(持续/同时).

  1. Iterate the list (for/while).

对于列表中的每个元素,请附加<element-of-list>.提示:在StringBuilder上使用append().

For each element in the list append <element-of-list>. Hint: use append() on StringBuilder.

截断/子串列表以删除最后添加的元素.提示:在String类上使用子字符串.

Truncate/substring the list to remove the last element added. Hint: use substring on String class.

这篇关于如何为列表中的每个字符串添加或插入'(单引号),其中使用Java用逗号分隔字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆