Login
|
Signup
langref.org
-
python
,
clojure
,
fsharp
,
fantom
...
add..
all
csharp
erlang
groovy
haskell
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Lists
Access
Fetch an element of a list by index
Given the list
[One, Two, Three, Four, Five]
, fetch the third element (
'Three'
)
python
list = ['One', 'Two', 'Three', 'Four', 'Five']
list[2]
list = ['One', 'Two', 'Three', 'Four', 'Five']
list[2]
clojure
(nth '[One Two Three Four Five] 2)
(nth '[One Two Three Four Five] 2)
fsharp
let result = List.nth ["One"; "Two"; "Three"; "Four"; "Five"] 2
#light
open System
let result = List.nth ["One"; "Two"; "Three"; "Four"; "Five"] 2
printfn "%s" result
fantom
["One", "Two", "Three", "Four", "Five"][2]
class SolutionXX
{
Void main()
{
["One", "Two", "Three", "Four", "Five"][2]
}
}
fantom
["One", "Two", "Three", "Four", "Five"].get(2)
class SolutionXX
{
Void main()
{
["One", "Two", "Three", "Four", "Five"].get(2)
}
}
java
String result = list.get(2);
import java.util.List;
import java.util.Arrays;
public class Solution389 {
public static void main(String[] args) {
List<String> list = Arrays.asList(new String[]{"One", "Two", "Three", "Four", "Five"});
String result = list.get(2);
System.out.println(result);
}
}
cpp
C++/CLI .NET 2.0
String^ result = list[2];
using namespace System;
using namespace System::Collections;
int main()
{
array<String^>^ input = {"One", "Two", "Three", "Four", "Five"};
Generic::List<String^>^ list = gcnew Generic::List<String^>((Generic::IEnumerable<String^>^) input);
String^ result = list[2];
}
go
fmt.Println(list[2])
package main
import "fmt"
func main() {
list := []string{"One", "Two", "Three", "Four", "Five"}
fmt.Println(list[2])
}
Submit a new solution for
python
,
clojure
,
fsharp
,
fantom
...
There are 17 other solutions in
additional
languages (
csharp
,
erlang
,
groovy
,
haskell
...)