You can do it like this:
s = s.replace("a[0]", s1[0]).replace("a[1]", s1[1])
The only issue is that you have no ‘a[1]’ substring in your string – there just ‘[1]’ – let’s think it’s just a typo.
More Related Contents:
- Java: Find word in string and edit words after the word
- How do I compare strings in Java?
- String.equals versus == [duplicate]
- String replace method is not replacing characters
- How do I count the number of occurrences of a char in a String?
- How to unescape a Java string literal in Java?
- Converting A String To Hexadecimal In Java
- Splitting on comma outside quotes
- Java Strings: “String s = new String(“silly”);”
- Java String replace not working [duplicate]
- What’s the best way to build a string of delimited items in Java?
- How to sort an array of objects in Java?
- How to split a string between letters and digits (or between digits and letters)?
- How can non-ASCII characters be removed from a string?
- How to capitalize the first letter of a String in Java?
- Fastest way to iterate over all the chars in a String
- Using Enum values as String literals
- How to check if a string contains only digits in Java
- Java String.indexOf and empty Strings
- Split a string, at every nth position
- Add spaces between the characters of a string in Java?
- == and .equals() not working in java [duplicate]
- Java: removing numeric values from string
- String concatenation with Null
- Problems with newline in Graphics2D.drawString
- Java way to check if a string is palindrome [duplicate]
- Reverse String Word by Word in Java
- Split string with | separator in java
- Convert Java Date into XML Date Format (and vice versa)
- Demonstrating string comparison with Java