I'm coming to F# from a C# background and a little behind on the different lists and collections. I recently ran into a case where I needed to go from a string[] to 'T list. I ended up using list comprehension to do the cast:
let lines = File.ReadAllLines(@"C:\LinesOText.txt") // returns a string array
let listOLines = [for l in lines -> l] // use list comprehension to get the f# list
Is there a more efficient way of doing the conversion?
So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.
Atoi is the fastest I could come up with. I compiled with msvc 2010 so it might be possible to combine both templates.
Use List.ofArray
or Array.toList
.
this should do it:
let lines = File.ReadAllLines(@"C:\LinesOText.txt") |> List.ofArray
Here's another way to do it:
let listOfLines = [yield! File.ReadAllLines(@"C:\LinesOText.txt")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With