[Solved] MapReduce to Spark

This is a very broad question, but the short of it is: Create an RDD of the input data. Call map with your mapper code. Output key-value pairs. Call reduceByKey with your reducer code. Write the resulting RDD to disk. Spark is more flexible than MapReduce: there is a great variety of methods that you … Read more

[Solved] How to print out possible string with alphabet set and length? [closed]

Use backtracking. void print_all(char []ch,int maxLen){ for(int i=1;i<=maxLen;i++) backTrack(ch,i,0,new char[i]); } void backTrack(char[] ch,int len,int k,char[] ans){ if(k==len){ System.out.print(new String(ans,0,len)+”,”); return; } for(int i=0;i<ch.length;i++){ ans[k]=ch[i]; backTrack(ch,len,k+1,ans); } } 1 solved How to print out possible string with alphabet set and length? [closed]

[Solved] java.lang.ArrayIndexOutOfBoundsException when adding new elements to an array? [closed]

This works for me. public class PersonService { protected int lastItemInPersonArray = 0; private Person[] persons = new Person[100]; public void addPersonToPersonArray(Person personToAdd) { persons[lastItemInPersonArray++] = personToAdd; } public static void main(String[] args) { PersonService ps = new PersonService(); ps.addPersonToPersonArray(new Person(“P 1”)); ps.addPersonToPersonArray(new Person(“P 2”)); ps.addPersonToPersonArray(new Person(“P 3”)); System.out.println(ps.persons[0].nome); System.out.println(ps.persons[1].nome); System.out.println(ps.persons[2].nome); } } class Person{ … Read more

[Solved] more than one type in Arraylist

This is not the proper way, but you can do something like this, ArrayList<Object> objects = new ArrayList<>(); objects.add(1); objects.add(“asd”); The better way is to create a different class with the attributes with Strings and int values you want. Then create an array with the type of that class and add those objects to the … Read more

[Solved] can someone please elaborate the following code?

The line: ch[i] = (char)(ch[i] – ‘a’ + ‘A’); Sets ch[i] to its associated uppercase due to a constant difference between an uppercase letter and its lowercase form. For means of communication, the line can be re-written as: ch[i] = (char)(ch[i] + (‘A’ – ‘a’)); By adding this constant difference the line yields the lowercase … Read more

[Solved] REGEX with two capturing groups

You can use this regex: <result1>(.*?)<result1>(?:(?:.(?!<result1>))*?<result>(.*?)<result>)? Can get your text in group #1 and group #2 (if exists). This regex will give: MATCH 1 1. `A1` 2. `B1` MATCH 2 1. `A2` MATCH 3 1. `A3` 2. `B3` RegEx Demo solved REGEX with two capturing groups

[Solved] Read yml file and convert it to HashMap instead of LinkedHashMap

I was able to solve using below solution. Now I can create multiple combinations and all are working fine. Hope somebody will find it helpful. package com.example; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class … Read more

[Solved] How to set the right path to image in java?

Have a look at MKYong’s tutorial. It shows you where to put your image. If you want the image to be loaded as “resource”, you have to put it in the resources folder. You project structure would be like this: MyProject +–src +–main +–java | +-com | +–me | +–Main.java +–resources +–pepsi.jpg and in your … Read more

[Solved] Parse JSON objects(lat and lng) in GoogleMap as markers

Please have a look at this line: for(Shop shop : this.response.shops){ map.addMarker(new MarkerOptions().position(new LatLng(shop.getShopLat(), shop.getShopLng())).title(shop.getShopAddress())); } In this line you want to create a new LatLng() object by adding into constructor an array instead of one value, change this line into: for(Shop shop : this.response.shops){ //remember to check is shop.getShopLat() is not null etc.. for(int … Read more

[Solved] Trying to write a program that calculates the amount of days a person is from they date of birth(19880101) using GregorianCalander class in Java

Trying to write a program that calculates the amount of days a person is from they date of birth(19880101) using GregorianCalander class in Java solved Trying to write a program that calculates the amount of days a person is from they date of birth(19880101) using GregorianCalander class in Java