Linked Questions

200 votes
19 answers
390k views

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) { ...
Jagmal's user avatar
  • 5,996
102 votes
6 answers
153k views

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+...
EugeneP's user avatar
  • 12.1k
34 votes
5 answers
17k views

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 ...
fortran's user avatar
  • 76.6k
16 votes
2 answers
42k views

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 ...
Alp's user avatar
  • 29.9k
0 votes
1 answer
2k views

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 ...
sar's user avatar
  • 1,281
0 votes
9 answers
432 views

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 $...
DVK's user avatar
  • 130k
-1 votes
4 answers
159 views

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-...
G.S's user avatar
  • 11k
-1 votes
2 answers
312 views

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 | ...
Julian Carrier's user avatar
0 votes
2 answers
276 views

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 ...
TheStranger's user avatar
  • 1,599
-2 votes
2 answers
136 views

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("...
St.Antario's user avatar
  • 27.8k
0 votes
2 answers
185 views

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 ...
Merna George's user avatar
-1 votes
3 answers
141 views

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 ...
Nicky 's user avatar
  • 71
0 votes
3 answers
123 views

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"); ...
OPK's user avatar
  • 4,200
-1 votes
1 answer
82 views

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
DevUt's user avatar
  • 1,288
0 votes
1 answer
33 views

I use this code to return a list from REST endpoint: private String getCurrencies(Integer id) { List<CurrencyDTO> list = null; try { list = StreamSupport.stream(...
Peter Penzov's user avatar
  • 1,194

15 30 50 per page