Quick Tip — How to convert a Java List to a Java String

Solution

List<Integer> my_list; // some code to fill the list ...
StringBuilder sb = new StringBuilder();
for (int i = 0; i < my_list.size(); ++i) {
sb.append(my_list.get(i));
if(i != my_list.size() - 1) {
sb.append(", ");
}
}
String s = sb.toString();

Explanation

Interesting links

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ViewPager in Jetpack Compose with dot indicators (within minutes)

Use of Binds and Provides in Hilt (Hilt Part 2)

Apollo GraphQL for Android

Improve code quality with ktlint, detekt, and git hooks

How to improve your daily work using proxy and mock tools

How to Open Full Play Store on Google TV

How to Open Full Play Store on Google TV

A beautiful, easy to use and customizable time planner for Flutter

Daily progression: Preparing for Android development in Unity on Linux Mint 20.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xavier Jouvenot

Xavier Jouvenot

More from Medium

Factory Method pattern in Java

Naming Conventions in Java

Testing azure functions in Java

ArrayList in Java