public class SplitStr { public static void main(String []args) { String str1 = "This | is | My | Account | For | Java|"; String str2 = "This / is / My / Account / For / Java/"; // String[] arr = str.split("|"); for(String item : str1.split("|")) { System.out.print(item); } } }
The program works correctly with the string str2, but does not work with the string str1. What are the possible threads in this program?
String#split() . | . , , |, \| . \ Java. , Java , \| , "\\|" String#split().
String#split()
|
\|
\
"\\|"
str1.split("\\|")
str1.split("|")
split , | , . str.split("\\|"). :
split
str.split("\\|")
>>> Arrays.asList("This | is | My | Account | For | Java|".split("\\|")); [This , is , My , Account , For , Java]
Source: https://habr.com/ru/post/1548602/More articles:specification / definition of file format ini - fileHow to connect from Google App Engine via static IP - google-app-enginePaginate sub-resources in Spring Data Rest 2.1 - springLeft join with dynamic table name derived from column - sqlPagination in Spring Saving Data for Nested Resources - javajava.lang.NoClassDefFoundError: android.os.AsyncTask - androidHow to check toast message in selendroid - javaUse case for pagination of embedded resources - spring-dataLine of points between points - cssSpring Data REST: How to get many elements using a list of identifiers in a single call? - javaAll Articles