Concatenate the strings in input that start with a ':'.
String s; // current input string String stot; // variable used as accumulator stot = ""; // "" is the neutral element for concatenation s = JOptionPane.showInputDialog("Input a string"); while (s != null) { if (s.charAt(0) == ':') stot = stot + s; s = JOptionPane.showInputDialog("Input a string"); } System.out.println("total string = " + stot);