1

Hii Guys !!! I have a string with values like 69 17 17 16 2 1 1 26 26 56 56 69 20 19 20 etc .Now As per my need i have to put these values into new String with each values in new line as after each value space is there ..

Any help will be highly appreciated.. Thanx in advance...

2
  • 1
    @freebird yes Sir ..I tried with '/n' but it didnt worked.. Commented Oct 11, 2012 at 6:54
  • you should also reassign your string. str.replace() call doesn't change str, but str = str.replace() does. ok? check my solution. Commented Oct 11, 2012 at 7:02

2 Answers 2

2
String newStr = origStr.replaceAll(" ", " \n");
Sign up to request clarification or add additional context in comments.

Comments

0

You should split the String using a specific separator into a List. Then print out the List using the format required. This helps when tomorow the String contains digits, decimals, text, etc or they want the text in another format.

    String source = "69 17 17 16 2 1 1 26 26 56 56 69 20 19 20";
    String[] splitted = source.split(" ");
    StringBuilder sb = new StringBuilder();
    for (String split : splitted){
        sb.append(split).append(System.getProperty("line.separator"));
    }
    System.out.println(sb.toString());

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.