+ 1
Combining replaceAll String
Hi, I like to know from my attached code, how do I use replaceAll method in one line instead of creating another string? https://code.sololearn.com/cxb375wCJMSQ/?ref=app
4 Respuestas
+ 5
import java.util.Arrays;
public class Program
{
public static void main(String[] args) {
int a[] = {1, 2, 3, 4, 5, 6};
String star = Arrays.toString(a).replaceAll("\\[|\\]|,|\\s", "").replace("2", "").replace("", ",");
System.out.println(star);
//System.out.println(newStar);
// System.out.println(newStarNew);
// combining as stream
star = Arrays.toString(a).replaceAll("\\[|\\]|,|\\s2","").replace(" ", ",");
System.out.println(star);
// single substring regex..
star = Arrays.toString(a).replaceAll("\\[|\\]|\\s|2,","");
System.out.println(star);
}
}
// 1,3,4,5,6 is what you trying I think..
+ 2
Thank you
+ 1
Where is code attached?
+ 1
Sorry, now attached!