Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Splitting a String and using the second part only in java

I have a list of string like this:

private List<String> repositoryTitle;

this contains 3 values:

yashwantyj97/test,
yashwantyj97/brokencrystals,
yashwantyj97/petclinic

I want a list which contains these 3 values:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

test, brokencrystals, petclinic

How to achieve this result dynamically?

>Solution :

Split them, and take the element at index 1.

repositoryTitle.stream()
   .map(str -> str.split("/")[1])
   .collect(Collectors.toList())

It will throw an exception if they don’t contain a slash, so you might want to filter them first.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading