Suppose you have a string with | characters in it. Since | is a regular expression character we need to escape it while splitting the string like below.
String[] tokens = str.split("\\|");
App.java
package com.sample.app;
public class App {
 public static void main(String args[]) {
  String str = "Hello|How|Are|You";
  
  String[] tokens = str.split("\\|");
  
  for(String token : tokens) {
   System.out.println(token);
  }
 }
}
Output
Hello
How
Are
You
No comments:
Post a Comment