List <String> list = new ArrayList <String> ();
如何把String长度最长的弄出来
------解决方案--------------------
循环这个List在循环里面做判断
------解决方案--------------------
楼上的方法可以考虑!
------解决方案--------------------
遍历吧
------解决方案--------------------
做循环吧
------解决方案--------------------
String str = " ";
int max = 0;
for(String string : list)
{
max = Math.max(max,string.length());
if(max == string.length())
str = string;
}
System.out.println( "max length string is: " + str + ",length is: " + max);
------解决方案--------------------
List <String> l = new ArrayList <String> ();
l.add( "ssd ");
l.add( "dsfsdsdd22dfsdfsdf ");
l.add( "werweewr " );
l.add( "dsfsdsdfsdfsdf ");
Collections.sort(l);
System.out.println(l.get(0));
------解决方案--------------------
关注
------解决方案--------------------
String str = " ";
int max = 0;
for(String string : list)
{
max = Math.max(max,string.length());
if(max == string.length())
str = string;
}
System.out.println( "max length string is: " + str + ",length is: " + max);
好好的调用什么Math.max()啊...
int length = str.length();
if (max < length) {
max = length
resultStr = str;
}