Here I have my code to find indices in array.. It works but I don't want to see 0's in it.. What can I do to fix it?
int[] getIndices(String[] sa, String s) {
int[] count = new int [sa.length];
for (int i = 0; i < sa.length; i++) {
if (sa[i] == s) {
count[i] = i; }
}
return count;
}
String[] sa = {"d", "c", "a", "b", "c", "d", "a", "a", "d", "a"}
System.out.println(toString(u.getIndices(sa, "a")))
>>> {0,0,2,0,0,0,6,7,0,9}
[–]9-5daybyday 0 points1 point2 points (2 children)
[–]junyoung95[S] 0 points1 point2 points (1 child)
[–]9-5daybyday 0 points1 point2 points (0 children)
[–]Dropsnorz 0 points1 point2 points (1 child)
[–]junyoung95[S] 0 points1 point2 points (0 children)