Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
in Salesforce by (11.9k points)

Using Apex, I want to split a string and then rejoin it with the 'AND' operator as the separator.

I split the string successfully but having an issue in rejoining it.

String [] ideaSearchText = searchText.Split(' ');

 // How to rejoin the array of strings with 'AND'?

How can I do this?

1 Answer

+1 vote
by (32.1k points)
edited by

You can join an array of strings by using String.join( ) for String[]

String input = 'valueOne valueTwo valueThree'; 

String[] values = input.split(' '); 

String result = String.join( values, ' AND ' );

Are you interested in learning Salesforce! Have a look at interesting video on SQL:

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...