# Java - Get value out of the feeder

**URL:** <https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456>\
**Category:** Gatling (Open-Source)\
**Created:** [February 16, 2022, 9:27am UTC](https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456 "2022-02-16T09:27:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharath\_Marrivada](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@Bharath\_Marrivada](https://community.gatling.io/u/Bharath_Marrivada)\
**Post date:** [February 16, 2022, 9:27am UTC](https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456/1 "2022-02-16T09:27:04Z")

</div>

Hello Stephan,

I have implemented the Gatling code in a function and called it from the main class. I need to get the value out of the feeder and send it to the function. Following is the sample code. Request your help on the same.

Iterator\<Map\<String, Object\>\> feeder1 =  
Stream.generate((Supplier\<Map\<String, Object\>\>) () → {  
int num = (int)Math.floor(Math.random()\*(100-10+1)+10);  
return Collections.singletonMap(“number”, num);  
}  
).iterator();

private ScenarioBuilder scn = scenario(“homePage”)  
.feed(feeder1)  
.exec(http(“Page”).get("/computers?p=#{number}"));  
.exec(gotoPage(2)) **//Want to replace 2 with #{number}**

Regards,  
Bharath.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 16, 2022, 9:57am UTC](https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456/2 "2022-02-16T09:57:03Z")

</div>

Then your goto method can’t take an Int. Make it take a String or a Function.

Moreover, you should probably switch to Java instead of Scala.

---

<div class="post-metadata">

**Author:** ![Bharath\_Marrivada](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@Bharath\_Marrivada](https://community.gatling.io/u/Bharath_Marrivada)\
**Post date:** [February 16, 2022, 10:25am UTC](https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456/3 "2022-02-16T10:25:18Z")

</div>

Thank you, Stephan, I have fixed it. I am using Java only.

**I have observed that you are suggesting using Java than Scala. May I know the reason?**  
In one of the youtube videos, you told that Java compilation is faster than Scala. Any differences between Java & Scala in terms of code execution?

Following is the working code.

Iterator\<Map\<String, Object\>\> feeder1 =  
Stream.generate((Supplier\<Map\<String, Object\>\>) () → {  
int num = (int)Math.floor(Math.random()\*(100-10+1)+10);  
return Collections.singletonMap(“number”, String.valueOf(num));  
}  
).iterator();

private ScenarioBuilder scn = scenario(“homePage”)  
.feed(feeder)  
//.exec(homePage())  
.exec(gotoPage("#{number}"))  
.exec(http(“Page”).get("/computers?p=#{number}"));

Regards,  
Bharath.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 16, 2022, 9:16pm UTC](https://community.gatling.io/t/java-get-value-out-of-the-feeder/6456/4 "2022-02-16T21:16:09Z")

</div>

> **I have observed that you are suggesting using Java than Scala. May I know the reason?**
