I want to take input from user in String array. Delete few parts of it and print it out in different text area block.
For example:
Input in String array.
===========
Mr: Alex Simmons
Miss: Susan Kent
Mrs: J. Peterson
===========
I want the output to look something like this.
After removing Mr:, Miss:, Mrs: rest of the values in a single line or element
===========
Alex Simmons Susan Kent J. Peterson
===========
Here is the code i am working with.
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
String[] names = jTextArea11.getText().split("\\n");
List<String> myList = new ArrayList<>(Arrays.asList(names));
myList.remove("Mr:");
myList.remove("Miss:");
myList.remove("Mrs:");
names = myList.toArray(new String[0]);
jTextArea12.setText(Arrays.toString(names));
}
The above code isn't seems to be working out for me..
Output is:
[Mr: Alex Simmons, Miss: Susan Kent, Mrs: J. Peterson]
"[ ]" braces at the end and separated by "," is not what i had in mind. Also the remove() isn't seems to be working.
.remove()operates on the list itself, not on the elements of the list. The remove would work if your list had somebody's name as literally justMr:, but you don't.jTextArea12.setText(String.join(" ", myList ));