我在网站上四处寻找一些类似的答案,但到目前为止我还没有找到任何东西。我想知道如何用预先建立的字符串填充字符串数组。另外,如果我有一个单独的类,我会将这段代码包含在方法中还是构造函数中?
字符串:
String stateList = "Alabama^Alaska^Arizona^Arkansas^California^Colorado^Connecticut^Delaware^Florida^"
+ "Georgia^Hawaii^Idaho^Illinois^Indiana^Iowa^Kansas^Kentucky^Louisiana^Maine^Maryland^"
+ "Massachusetts^Michigan^Minnesota^Mississippi^Missouri^Montana^Nebraska^Nevada^"
+ "New Hampshire^New Jersey^New Mexico^New York^North Carolina^North Dakota^Ohio^Oklahoma^"
+ "Oregon^Pennsylvania^Rhode Island^South Carolina^South Dakota^Tennessee^Texas^Utah^"
+ "Vermont^Virginia^Washington^West Virginia^Wisconsin^Wyoming";
我的尝试(没有奏效):
String[] stateArray = stateList.split(" ^ ");
for(int i=0; i < stateArray.length; i++)