Finding Largest String in ArrayList
package com.java.exp;
import java.util.ArrayList;
public class HighestCharinString {
public static void main(String[] args) {
ArrayList<String> al=new ArrayList<>();
al.add("Bangalore");
al.add("hyd");
al.add("jagan");
al.add("upenderathota");
//I would set your largestString variable to your first String that you add:
int largeststring=al.get(0).length();
int index=0;
for(int i=0;i<al.size();i++)
{
//Then you should use the following to check for the largest String:
if(al.get(i).length()>largeststring)
{
largeststring=al.size();
index=i;
}
}
System.out.println("Index " + index + " "+ al.get(index) + " " + "is the largest and is size " + largeststring);
}
}
//OUTPUT:Index 3 upenderathota is the largest
package com.java.exp;
import java.util.ArrayList;
public class HighestCharinString {
public static void main(String[] args) {
ArrayList<String> al=new ArrayList<>();
al.add("Bangalore");
al.add("hyd");
al.add("jagan");
al.add("upenderathota");
//I would set your largestString variable to your first String that you add:
int largeststring=al.get(0).length();
int index=0;
for(int i=0;i<al.size();i++)
{
//Then you should use the following to check for the largest String:
if(al.get(i).length()>largeststring)
{
largeststring=al.size();
index=i;
}
}
System.out.println("Index " + index + " "+ al.get(index) + " " + "is the largest and is size " + largeststring);
}
}
//OUTPUT:Index 3 upenderathota is the largest
Hey, thanks for the blog article. Really looking forward to read more. Cool.
ReplyDeletepython training
angular js training
selenium trainings
selenium trainings
ReplyDeletesql server dba training
Testing tool training