Using Java, I need to split a string into sections into an arrayList. Everything
ID: 644060 • Letter: U
Question
Using Java,
I need to split a string into sections into an arrayList. Everything between (and including the ) two consecutive capitalized letters would be extracted and put into an index in the ArrayList. Also the start of the string needs to be included up to the first set of two consecutive capitalized letters. For example if the string was: String testString = "Linda Dumas 3393 Pennsylvania Avenue Portland TX Huazhang Hanlon 3428 Main Road Miami NH ";
The output would be {Linda Dumas 3393 Pennsylvania Avenue Portland TX,Huazhang Hanlon 3428 Main Road Miami NH}
The actual string I have has about 200 addresses so I need to seperate them using the fact that each of them have two consecutive letters. I
Explanation / Answer
import java.util.ArrayList;
import java.util.Scanner;
?
public class Subset {
public static void main(String jk[]){
Scanner in = new Scanner(System.in);
String s;
System.out.println("Enter a statement");
s = in.nextLine();
ArrayList ik =new ArrayList();
for (char c : s.toCharArray()) {
if (Character.isUpperCase(c)) {
ik.add(c);
}
}
for(int j=0;j<ik.size();j++)
System.out.println(ik.get(j));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.