Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8258619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:36:17+00:00 2026-06-08T02:36:17+00:00

I am converting some of my java code to scala and I would like

  • 0

I am converting some of my java code to scala and I would like to be able to get a specific header and return it as a string.

In java I have:

return request().getHeader("myHeader")

I have been unable to achieve the same thing in scala. Any help would be greatly appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:36:20+00:00Added an answer on June 8, 2026 at 2:36 am

    You could write:

    request.get("myHeader").orNull
    

    If you wanted something essentially the same as your Java line. But you don’t!

    request.get("myHeader") returns an Option[String], which is Scala’s way of encouraging you to write code that won’t throw null pointer exceptions.

    You can process the Option in various ways. For example, if you wanted to supply a default value:

    val h: String = request.get("myHeader").getOrElse("")
    

    Or if you want to do something with the header if it exists:

    request.foreach { h: String => doSomething(h) }
    

    Or just:

    request foreach doSomething
    

    See this cheat sheet for more possibilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm converting some old Java code to Scala. I have this. class XYCustomRenderer(dataMax: Double,
I'm just beginning in scala and I'm converting some java code into scala and
I am converting some Java NIO code to run in Scala and I am
I am converting some Java code to C# and have found a few labelled
I have some code that I'm converting from Perl to Java. It makes pretty
I have some old 3rd party Java code I am converting to Java 6.
I am tasked with converting some Python code to Java. I have some experience
I am manually converting code from Java (1.6) to C# and finding some difficulty
I'm converting some Java code to Javascript, and the Java object has a Static
I am maintaining some Java code that I am currently converting to C#. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.