Linked Questions
60 questions linked to/from Java: convert List<String> to a join()d String
200
votes
19
answers
390k
views
Best way to concatenate List of String objects? [duplicate]
What is the best way to concatenate a list of String objects? I am thinking of doing this way:
List<String> sList = new ArrayList<String>();
// add elements
if (sList != null)
{
...
102
votes
6
answers
153k
views
Join String list elements with a delimiter in one step [duplicate]
Is there a function like join that returns List's data as a string of
all the elements, joined by delimiter provided?
List<String> join; ....
String join = list.join('+");
// join == "Elem 1+...
34
votes
5
answers
17k
views
Is there a direct equivalent in Java for Python's str.join? [duplicate]
Possible Duplicates:
What’s the best way to build a string of delimited items in Java?
Java: convert List<String> to a join()d string
In Java, given a collection, getting the ...
16
votes
2
answers
42k
views
Convert List<String> to delimited String [duplicate]
Possible Duplicate:
Java: convert List<String> to a join()d string
Having this:
List<String> elementNames = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6");
What is an elegant way ...
0
votes
1
answer
2k
views
Conditional statement in java8 forEach loop [duplicate]
I have string which contain number of department separated by comma.
I have to feed this data to sql 'IN' clause.
I want conditional check for last element, I do not want to append 'comma' after
...
0
votes
9
answers
432
views
What's the most elegant/concise way of printing all strings in a list into a single string? [duplicate]
Is there an elegant way (elegant meaning without an iterator or a loop) to print every member of Java's List<Sting> object into a comma-separated string?
E.g., Java's version of Perl's my $...
-1
votes
4
answers
159
views
Adding delimiter has any elegant way? [duplicate]
This is a simple java coding question.
I have a List of String [Say "hello" "how" "are" "you?"]. I need to insert a delimiter [-] between each element of the list so that my output is hello-how-are-...
-1
votes
2
answers
312
views
How can i write a function for a deck class toString method [duplicate]
Basically i have this toString method witch displays sorted cards. Essentially if i have a full deck of cards this is what the output would look like.
{Ace of Clubs | Two of Clubs | Three of Clubs | ...
0
votes
2
answers
276
views
How do I turn a Set<String> into a string in Java? [duplicate]
I have a Set<> of strings:
Set<String> mySet = new HashSet<String>();
hs.add("how");
hs.add("are");
hs.add("you");
I want to turn this set into a ...
-2
votes
2
answers
136
views
How to transform a list into a string? [duplicate]
I have the list of strings
List<String> lst;
I need to transform that list into a string as follows:
List<String> lst = new ArrayList<String>();
lst.add("String 1");
lst.add("...
0
votes
2
answers
185
views
Convert content of vector into word java [duplicate]
I'm trying to return and output the contents of a vector as a cohesive String. I tried vector.toString() but that would also include brackets and commas. I can't have that. Is there a way to convert ...
-1
votes
3
answers
141
views
How to remove [ ] from a Collection in Java? [duplicate]
I have a collection arraylist in Java.
For example when I do:
test is the collection.
System.out.println(test.getTester());
Why do I get the result of:
[jamesbond]
I only want jamesbond but why ...
0
votes
3
answers
123
views
Why still get [ ] after using toString method? [duplicate]
Here is my code:
public class StackStudy{
public static void main(String[] args){
Stack<String> st = new Stack<String>();
st.push("hi");
st.push("bye");
...
-1
votes
1
answer
82
views
list string to single string [duplicate]
I have a situation in which I want to convert a List<String> to a single String and with commas
PS : I'm using RootTools library for command and I wanna execute a
Busybox --list command
0
votes
1
answer
33
views
Convert list into String with values [duplicate]
I use this code to return a list from REST endpoint:
private String getCurrencies(Integer id) {
List<CurrencyDTO> list = null;
try {
list = StreamSupport.stream(...