The title says one day, but I started it about the day before yesterday, and did it take about eight hours in total? I thought, so I will summarize my impressions.
Often, "+" is used to combine strings in a loop. .. .. I see a typical article, but it's not the case of a combination of strings + numbers.
In Java
int bread = 13;
System.out.println("Do you remember how many breads you have ever eaten?");
System.out.println(bread + "I'm Japanese food");
I write it in a similar way.
With Golang (I'm sorry I omit import)
bread := 13
fmt.Println("Do you remember how many breads you have ever eaten?")
fmt.Printf("%d sheets I'm Japanese food\n", bread)
Will be.
After that, you can convert the type.
bread := 13
breadStr := strconv.Itoa(bread)
I wrote a syntax error when I wanted to return a value with a ternary operator. There isn't. .. ..
In Java
boolean isOk = true;
String text = isOk ? "OK" : "NG";
The guy.
With Golang
isOk := true
text := "NG"
if isOk {
text = "OK"
}
etc.
With Java8 and StreamAPI, I write more and more using method chains, but I can't do that. There is something similar to the extended for statement, but you need to be a little careful.
In Java
String[] array = {"a", "b", "c"};
//Stream API
Arrays.stream(array).peek(System.out::println);
//Extended for statement
for (String text : array) {
System.out.println(text);
}
The guy.
With Golang
NG.go
array := []string{"a", "b", "c"}
for text := range array {
fmt.Println(text)
}
That's no good
OK.go
array := []string{"a", "b", "c"}
for _, text := range array {
fmt.Println(text)
}
is not it. Since the range that can be used in the for statement is Multiple Return Values, the first return value is the index and the second return value is the value stored in the array. Please note that omitting the second case will not cause an error.
I haven't touched much about the asynchronous surroundings such as goroutine and channel, and the relationship between interface {} and type, so I'll write it after touching it a little more.
Go language is interesting! (Is it fun to learn a new language?)
I have some troubles when writing various things, but I thought it was relatively easy to get along with.
Recommended Posts