首页 > 编程知识 正文

java字符串类型转换为int,java输入字符串数组

时间:2023-05-05 20:20:23 阅读:9061 作者:3920

itoccuredtometodaythebehaviorofjavastring.split () is very strange。

Actually I want to split a string 'aa,bb,cc,dd,ee' to array by .split (,',',') that gives me a string array [ ],]

But when I try to split a String 'aa,bb,cc,dd,' toarraythisgivesmearrayoflength4means only [ ' aa ',' bb ',' cc

iwantaprocedurethatsplitsastringlike ' aa,bb,cc,dd,' aa ',' bb ',' cc ',',' dd ',' to aray

isthispossiblewithjava.lang.stringapi? 高级thanks in。

解决方案

' aa、bb、cc、dd、'.split (、'、-1) ) )。

whenstring.split(stringregex ) is called,it is called with limit=0,whichwillremovealltrailingemptystringsinthearray ) imith

theactualbehaviorofstring.split (字符串注册) is quite confusing:

splittinganemptystringwillresultinanarrayoflength1. emptystringsplitwillalwaysresultinlength1arraycontaingtheemptystring。

Splitting ';' 或'; ) )。 with regex being '; ' willresultinanemptyarray.non-emptystringsplitwillresultinalltrailingemptystringsinthearrayremoved。

thebehaviorabovecanbeobservedfromatleastjava5to Java 8。

therewasanattempttochangethebehaviortoreturnanemptyarraywhensplittinganemptystringinjdk-6559590.however, itwassoonrevertedinjdk-8028321 whenitcausesregressioninvariousplaces.thechangenevermakesitintotheinitialjava 8发行版。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。