import java.util.*; class UseArrayLists8 // Shows adding a string after all occurrences of a string // constructively in an ArrayList { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); System.out.println("Enter some words (all on one line, separated by spaces):"); String line = input.nextLine(); String[] words = line.split(" "); ArrayList a = new ArrayList(); for(int i=0; i b=addAfter(a,p,q); System.out.println("\nThe ArrayList created is "+b); System.out.println("The original ArrayList is still "+a); } public static ArrayList addAfter(ArrayList a,String m,String n) // Adds n after every occurrence of m in a, constructively. { ArrayList b = new ArrayList(); for(int i=0; i