Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to parse URL in Scala

1 Answer

0 votes
import java.net.URL

object URLParser extends App {
  val url = new URL("https://collectivesolver.com:8080/path?query=scala#fragment")

  // Extracting different parts of the URL
  val protocol = url.getProtocol
  val host = url.getHost
  val port = url.getPort
  val path = url.getPath
  val query = url.getQuery
  val fragment = url.getRef

  println(s"Protocol: $protocol")
  println(s"Host: $host")
  println(s"Port: $port")
  println(s"Path: $path")
  println(s"Query: $query")
  println(s"Fragment: $fragment")
}
 
   
   
/*
run:
     
Protocol: https
Host: collectivesolver.com
Port: 8080
Path: /path
Query: query=scala
Fragment: fragment
 
*/

 



answered Feb 1, 2025 by avibootz

Related questions

2 answers 224 views
224 views asked Feb 1, 2025 by avibootz
1 answer 110 views
110 views asked Feb 1, 2025 by avibootz
1 answer 104 views
104 views asked Feb 1, 2025 by avibootz
1 answer 75 views
1 answer 75 views
1 answer 43 views
43 views asked Jan 31, 2025 by avibootz
...