java - Iterating String Array by a specific value -
this question has answer here:
- how can test if array contains value? 23 answers
i'm iterating on arraylist string arrays inside.
["a","1"] ["a","2"] ["a","3"] ["b","1"] ["b","2"] ["b","3"]
how can select ones "a" on first position? without iterating, , saving on new array...
for (string[] key : keys){ }
using each example, want is, first iteration -> work string arrays "a", second iteration -> work string arrays "b".
try this:
string[][] keys = { {"a","1"}, {"a","2"}, {"a","3"}, {"b","1"}, {"b","2"}, {"b","3"}, }; string[][] result = stream.of(keys) .filter(x -> x[0].equals("a")) .toarray(string[][]::new); system.out.println(arrays.deeptostring(result));
Comments
Post a Comment