java 字符串数组查询,Java的:查找数组列表字符串

My arraylist consists of an array with a list of strings, each string inside is separated by commas, i want to split one of the strings into substrings divided by the commas, i know how to do it to arrays by using the split method, but im having trouble finding something similar to array lists, heres the code:

String[] widgets2 =

{

"1,John,Smith,John1989@gmail.com,20,88,79,59",

"2,Suzan,Erickson,Erickson_1990@gmailcom,19,91,72,85",

"3,Jack,Napoli,The_lawyer99yahoo.com,19,85,84,87",

"4,Erin,Black,Erin.black@comcast.net,22,91,98,82",

"5,Adan,Ramirez,networkturtle66@gmail.com,100,100,100"

};

ArrayList jim = new ArrayList(Arrays.asList(widgets2));

System.out.println(jim.split(0));

解决方案

It is similar to what you do with the arrays. Just that the implementation is different. To get the values just loop through them:

List jim = new ArrayList(Arrays.asList(widgets2));

for(String currentString : jim){//ArrayList looping

String[] separatedStrings = currentString.split(",");

for(String separatedString : separatedStrings){//Now its array looping

//Do something now whatever you like to

}

}

If you want to have the index and decide which value to get, use normal for loop using index and use jim.get(index) and use split().

Having said that, what stops you from looping through the List ? It's the common usage of array list - to loop through it :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值