For a string "a3tx2z" The output of this should be "attttxzzz", or for "12x" it should be "2xxx". I checked everything and they work. but when i want to print "ttt" in the place of 3, there is a java.lang.UnsupportedOperationException
at line 28 l.add(i, s1);
. What is wrong here?
package xyz;
import java.util.Arrays;
import java.util.List;
public class xyz {
public static void main(String[] args) {
xyz n = new xyz();
n.blowup("a3tx2z");
}
public String blowup(String str){
String[] array = str.split("");
List<String> l = Arrays.asList(array);
for(int i=0; i<l.size(); i++){
String s1 = l.get(i);
if(s1.matches("-?\\d+(\\.\\d+)?")){
String s2 = l.get(i+1);
if(!(s2.matches("-?\\d+(\\.\\d+)?"))){
int t = Integer.parseInt(s1);
while(t>0){
l.add(i, s1);
t--;
}
}
}
}
for(String x: l){
System.out.print(x);
}
return "";
}
}