TAILIEUCHUNG - Bắt đầu với IBM Websphere smash - p 13

102 Chapter 5 Global Context Listing Testing if the Global Context Contains a Particular Variable if([]) { //do something } Like zcontains, this can be used as a guard code that needs to have particular variables available. In Groovy, there are no shortcuts for other Java methods, so we would just use the Java version in Groovy. Lists Just like Java, in Groovy, lists are indexed lists of objects. To put a single list variable into the global context in Java, we use the zput method. zput Method To put a list into the global context, we use the zput method: boolean zput(String location, List list); In. | 102 Chapter 5 Global Context Listing Testing if the Global Context Contains a Particular Variable if do something Like zcontains this can be used as a guard code that needs to have particular variables available. In Groovy there are no shortcuts for other Java methods so we would just use the Java version in Groovy. Lists Just like Java in Groovy lists are indexed lists of objects. To put a single list variable into the global context in Java we use the zput method. zput Method To put a list into the global context we use the zput method boolean zput String location List list In Groovy we can simply make a direct assignment 42 string object With this code we ve created a list and directly created or replaced the list in the tmp zone. We can replace single elements of our stored list by using array style indexes to specify where to put the value 1 new string This replaces string object with new string in our stored list. zpost Method To append to a list in the global context we use zpost in Groovy just like we do in Java. Please refer to the previous section on Java. zget Method In Java to retrieve lists placed in the global context we use the zget method Object zget String location Object defaultvalue In Groovy we can access lists in the global context directly see Listing . Listing Retrieving Lists from the Global Context with Groovy var slist var ilist Download from Accessing the Global Context 103 Here we are retrieving our string and integer lists and assigning them to a Groovy variable directly. We can also retrieve individual elements from our list by again using the array style indexing notation see Listing . Listing Retrieving an Element from a List var s 0 var i 0 This code retrieves the first element of each list. zdelete Method To remove a list from the global context we use zdelete in Groovy just like we do in Java. Please

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.