---
title: "Use split method with stringbuilder together in the same class?"  
description: "Use split method with stringbuilder together in the same class?"  
author: "Anonymous User"  
published: 2015-12-22  
updated: 2015-12-22  
canonical: https://www.mindstick.com/forum/33774/use-split-method-with-stringbuilder-together-in-the-same-class  
category: "java"  
tags: ["java", "string"]  
reading_time: 3 minutes  

---

# Use split method with stringbuilder together in the same class?

[StringBuilder](https://www.mindstick.com/forum/34633/stringbuffer-and-stringbuilder) to hide vowels:\

```
String bienvenue_intro = " Welcome! Java First Semester: 455, java street: City (State): Country: 575757 ";            StringBuilder sb = new StringBuilder(bienvenue_intro);             String[] introduction = bienvenue_intro.split(":");             for (int i = 0; i < bienvenue_intro.length(); i++)            {                char c = bienvenue_intro.charAt(i);                if (   (c == 'A') || (c == 'a')                     || (c == 'E') || (c == 'e')                     || (c == 'I') || (c == 'i')                     || (c == 'O') || (c == 'o')                     || (c == 'U') || (c == 'u'))                {                    sb.setCharAt(i, '*');                }            }            System.out.println(bienvenue_intro);;            System.out.println(sb.toString());
```

\
The [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) of the above [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is:\

```
Welcome! Java First Semester: 455, java street: City (State): Country: 575757  W*lc*m*! J*v* F*rst S*m*st*r: 455, j*v* str**t: C*ty (St*t*): C**ntry: 575757 
```

[Method](https://www.mindstick.com/forum/166/webservice-method) [split](https://www.mindstick.com/blog/11920/top-3-voltas-split-acs-for-your-home) to break the lines:\

```
for (int i = 0; i < introduction.length; i++)            System.out.println(introduction[i]);
```

The desired output using split + [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [builder](https://www.mindstick.com/articles/12472/mgs-front-end-builder-for-magento-2-best-selling-product-on-magento-marketplace) would be:\

```
W*lc*m*! J*v* F*rst S*m*st*r 455, j*v* str**t C*ty (St*t*) C**ntry 575757 
```

But both [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-together) it does not work! Is it even possible to [team](https://www.mindstick.com/articles/157065/5-ways-to-build-a-great-working-team) StringBuilder with the Split method?

## Replies

### Reply by Anonymous User

Don't split the String before, first to the transformation. StringBuilder will perform the in-place character replacement for you and get the replaced String using toString() and perform the split on it.

```
String bienvenue_intro = " Welcome! Java First Semester: 455, java street: City (State): Country: 575757 ";StringBuilder sb = new StringBuilder(bienvenue_intro);for (int i = 0; i < bienvenue_intro.length(); i++) {  char c = bienvenue_intro.charAt(i);  if (   (c == 'A') || (c == 'a')      || (c == 'E') || (c == 'e')      || (c == 'I') || (c == 'i')      || (c == 'O') || (c == 'o')      || (c == 'U') || (c == 'u')) {    sb.setCharAt(i, '*');  }}System.out.println(bienvenue_intro);//System.out.println(sb.toString());String[] introduction = sb.toString().split(":");  //<-- Do the split here after replacements.for (String string : introduction) {  System.out.println(string);}
```

Output:

```
 W*lc*m*! J*v* F*rst S*m*st*r 455, j*v* str**t C*ty (St*t*) C**ntry 575757 
```


---

Original Source: https://www.mindstick.com/forum/33774/use-split-method-with-stringbuilder-together-in-the-same-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
