Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. public class Strings{
  2.     public static void swapMaxes(List<String> list1, List<String> list2){
  3.     if(list1 == null || list2 == null || list1.size() == 0 || list2.size()==0){
  4.     throw new IllegalArgumentException("cannot swap maxes of empty lists, null lists, or lists with all null elements");
  5.    
  6.     int longString1 = 0;
  7.     int position1;
  8.     for(int i = 0; i < list1.size(); i ++) {
  9.         if(list1.get(i).length() > longString1) {
  10.             longString1 = list1.get(i).length();
  11.             position1 = i;
  12.         }
  13.     }
  14.     int longString2 = 0;
  15.     int position2;
  16.     for(int j = 0; j < list2.size(); j ++) {
  17.         if(list2.get(j).length() > longString2) {
  18.             longString1 = list1.get(j).length();
  19.             position1 = j;
  20.         }
  21.     }
  22.     }          
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement