Tuesday, 15 June 2010

java - Counting instances of a string in a nested ArrayList -



java - Counting instances of a string in a nested ArrayList -

in below example, how go counting amount of times 'yes' occurs , depending on how many times occurs, store value variable? e.g. if 'yes' occurs 1 time 10, twice 30, etc. i'm quite new info structures , sense maybe going wrong way. advice appreciated.

import java.util.arraylist; public class details { public static void main(string[] args) { arraylist<string> al1 = new arraylist<string>(); al1.add("hi"); al1.add("how you"); al1.add("good morning"); al1.add("bye"); al1.add("good night"); arraylist<string> al2 = new arraylist<string>(); al2.add("howdy"); al2.add("good evening"); al2.add("bye"); al2.add("good night"); arraylist<arraylist<string>> al4 = new arraylist<arraylist<string>>(); al4.add(al1); // storing comparing output in arraylist<string> arraylist<string> al3 = new arraylist<string>(); (string temp : al1) al3.add(al2.contains(temp) ? "yes" : "no"); system.out.println(al3); } }

arraylist<arraylist<string>> al4 = new arraylist<arraylist<string>>(); int totalsize = 0 ; ( inti = 0 ; < al4.size() ; i++ ) { arraylist<string>> nested_al4 = al4.get(i); ( inti = 0 ; < nested_al4.size() ; i++ ) { totalsize ++ } } system.out.println(totalsize );

java string arraylist contains

No comments:

Post a Comment