Why none of these operations are working when I am trying to remove empty strings in my list?
This is my list:
(yuhindmklwm00409219,958193628,0305delete,2700)
(yuhindmklwm00409219,958193628,0305delete,800)
(yuhindmklwm00409219,959262446,0219delete,62)
()
(yuhindmklwm00437293,752013801,0220delete,2700)
()
()
()
(yuhindmklwm00437293,85382,0126delete,500)
()
(yuhindmklwm00437293,863056514,0326delete,-2700)
(yuhindmklwm00437293,863056514,0326delete,2700)
()
()
()
()
()
(yuhindmklwm00437293,85258,0313delete,1000)
(yuhindmklwm00437293,85012,0311delete,1000)
(yuhindmklwm00437293,85718,0311delete,2700)
()
()
()
()
()
()
()
(yuhindmklwm00437293,744622574,0322delete,90)
(yuhindmklwm00437293,83704,0215delete,17)
()
()
(yuhindmklwm00437293,85253,0331delete,-2700)
(yuhindmklwm00437293,85253,0331delete,2700)
()
()
()
()
()
()
()
()
(yuhindmklwm00437293,752013801,0305delete,2700)
(yuhindmklwm00437293,33165,0315delete,1000)
(yuhindmklwm00437293,85018,0319delete,100)
(yuhindmklwm00437293,85018,0219delete,100)
(yuhindmklwm00437293,85018,0118delete,100)
(yuhindmklwm00437293,90265,0312delete,6)
(yuhindmklwm00437293,02465,0312delete,25)
(yuhindmklwm00437293,857164939,0313delete,15)
(yuhindmklwm00437293,22102,0313delete,4)
(yuhindmklwm00437293,55423,0313delete,100)
(yuhindmklwm00437293,02465,0314delete,1)
(yuhindmklwm00437293,90265,0312delete,1)
(yuhindmklwm00437293,93108,0315delete,25)
(yuhindmklwm00437293,220432304,0315delete,35)
(yuhindmklwm00437293,701211570,0315delete,35)
(yuhindmklwm00437293,28801,0315delete,10)
(yuhindmklwm00437293,93108,0211delete,3)
(yuhindmklwm00437293,93108,02)
This is type of list: List[String] = List((yuhindmklwm00437293,93108,02)..........))
I tried filter:
outputList1.filter(_.isNotNull).size
and
outputList1.map(record => if (record.size>3) record) else None)
both these approaches are unable to remove empty strings. The size of the list remains same for both
outputList1.filter(_.nonEmpty)An emptyString, i.e."", is not the same thing asnull, andNoneis not the same type asString.outputList1.filter(_ != null).sizegives the same sizenullis not the same as""so anulltest won't find empty strings.outputList1.map(record => if (record.size>3) record else None)since I am just ignoring any string less than 3Noneis not the same type asString. The result of that would be a mixed collection ofStrings (greater than 3 characters) andNones, which is not what you want. Tryfilter(_.length > 3).