Question

JAVA need help creating method removeLongestString

List<String> listString = new ArrayList<String> ;

listString.clear ; 1istString.add (three) listString.add (four); remove LongestString(listString); System.out.println( li

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please go through code and output.

CODE:


import java.util.*;
import java.util.List;
import java.util.Arrays;


public class RemoveLongestString {
  
   public static void removeLongestString(List<String> listString)
   {
       int size = 0;
       int count = 0;
       String temp = "";
       for(int i=0; i<listString.size(); i++) // check max length and register it with count
       {
           temp = listString.get(i);
           if(size < temp.length())
           {
               size = temp.length();
               count = i;
           }
          
       }
       listString.remove(count); // remove max length string
   }
   public static void main(String[] args)
   {
       List<String> listString = new ArrayList<String>();
       listString.clear();
       listString.add("three");
       listString.add("four");
       removeLongestString(listString);
       System.out.println(listString);
   }
}

OUTPUT:

[four]

Add a comment
Know the answer?
Add Answer to:
JAVA need help creating method removeLongestString List<String> listString = new ArrayList<String> ; listString.clear ; 1istString.add ("three")...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT