title: Store HDFS file contents in ArrayBuffer using Spark Scala
body: <p>I am trying to search for a particular keyword and put the entire row associated with the word in array buffer. I am using the below sample and trying to put all the <strong>HHH</strong> in array buffer.</p>
  
  <p><strong>Sample</strong></p>
  
  <pre><code>PID|1|5897450M|58974650M|58977650M|CSTO^TES||19320722|F|||745 - 81 ST^^IAMI BEH^FL^341|||||||332165520
  ORC||5033220|503320||||||20150202|||1689659096^HAM^MISH^^^^PI
  OBR|1||64564|DF DEFAULT|||20150202|2015002||||||||16096^^^^^I|||||||||
  HHH|1|NM|6690-2^^LN^0^^L||7|XE/UL|3.4-18||||F|||20150202| ^^L
  HHH|9|NM|777-3^LOINC^LN^015172^PLATELETS^L||185|X10E3/UL|150-379||||F|||201202|TA   ^^L
  HHH|10|NM|770-8^^LN^015107^^L||65|%|||||F|||20150202|TA   ^^L
  HHH|11|NM|736-9^LOINC^LN^015123^^L||26|%|||||F|||20150202|TA   ^^L
  HHH|12|NM|5905-5^LOINC^LN^015131^^L||8|%|||||F|||20150202|TA   ^^L
  HHH|13|NM|713-8^LOINC^LN^015149^^L||1|%|||||F|||20150202|TA   ^^L
  </code></pre>
  
  <p>for achieving the goal i am writing this code:</p>
  
  <pre><code>import scala.collection.mutable.ArrayBuffer
  object WordCount {
  def main(args: Array[String])
  {
      var arrybufobx =  ArrayBuffer[String]()
      val textfile = sc.textFile("/user/cloudera/xxx/File")
      val word = textfile.filter(x =&gt; x.length &gt;  0).map(_.split('|'))
      val obx = word.filter(_.contains("HHH"))
      val obxkeys = obx.map(a =&gt; s"${a(0)},${a(5)},${a(8)}").toString()
      arrybufobx += obxkeys
      arrybufobx.foreach { println }
  }
  }   
  </code></pre>
  
  <p>but i am not able to see the contents of array buffer. I want to know how can i see my array buffer contents and is this the correct way to do this.</p>
  
  <p>Please help</p>