[Solved] How to create dynamic List

Map<String, List<String>> newMap = new HashMap<>(); for (Map.Entry<String, String> entry : masterList.entrySet()) { List<String> values = new LinkedList<>(); if (entry.getKey().startsWith(“tag_”)) { String[] words = entry.getValue().split(“,\\s*”); Collections.addAll(values, words); } else { values.add(entry.getValue()); } newMap.put(entry.getKey(), values); } One should not change the type of the map, so need to create a new map. solved How to create … Read more

[Solved] Getting IndexOutOfBound Android

In here: if (singleUserData.size() == 1) you seem to be checking that the size is of 1 element. But within that same scope, you are accessing multiple items. You would probably need to change this check: if (singleUserData.size() == 1) to if (singleUserData.size() == 5). 4 solved Getting IndexOutOfBound Android

[Solved] Constructor in Class cannot be applied to gives types [closed]

The constructor public HeartRates( String fName, String lName, int aMonth, int aDay, int aYear) of class HeartRates has the arguments String,String,int,int,int. So you have to provide those values in HeartRates profile = new HeartRates(); // need values as argument Some thing like:- // calling constructor with arguments HeartRates profile = new HeartRates(firstName, lastName, month, day, … Read more

[Solved] Inputting data in hash map of hash map in one loop or two single loops

Your problem description is unclear, but given your input file, the following probably does what you need: HashMap<String, HashMap<String, String>> repoUserMap = new HashMap<>(); for (int i = 0; i < data.size(); i++) { //data is an arraylist String[] seq = data.get(i).split(“,”); String repo = seq[0]; // Lookup the 2nd-level map, and create it if … Read more

[Solved] enhanced for loop (java) [duplicate]

You can do it using syntax like the following: for (String s: cdSporNavn){ if(s.indexOf(“java”) != -1){ System.out.println(s); } } See Using Enhanced For-Loops with Your Classes for further information and examples. 0 solved enhanced for loop (java) [duplicate]

[Solved] How can I make my own graphic interface? [closed]

Almost all programming languages have libraries that help you create a GUI (Graphical User Interface). Most programming languages, including C++, C#, and Java are general-purpose programming languages – you can use them to program whatever you want. For Java for example, see this tutorial: Creating a GUI With JFC/Swing. If you want to write an … Read more

[Solved] java regular expression take next value [closed]

If you want only the 12th value Using split: (very simply, a bit inefficient, but probably not too bad – I wouldn’t bother with anything else unless I’m writing production code) System.out.println(str.split(“,”)[12]); Using indexOf: (somewhat more complex, way more efficient) int index = 0; for (int i = 0; i < 12; i++) index = … Read more

[Solved] How to split string into an array? [closed]

Split the string into array: String x = “What is my name”; String[] splitted = x.split(” “); for (int i = 0; i < Array.getLength(splitted); i++) { System.out.println(“Word ” + (i+1) + “: ” + splitted[i]); } You can change System.out.println() to your desired output method. Edit (as suggested in comment): For safer code, change … Read more

[Solved] why there is error with spaces (” “) in arrays? [closed]

Looks like you’re trying to do something like this: static String HTMLchange(String src) { return src.replaceAll(“ber”, “vai”); } which replaces every occurrence of “ber” in the string with “vai” UPDATE using in.next() fetches the next token. Whitespace is considered as a legit delimiter so when the user enters the string “x ber x” the first … Read more

[Solved] Print asterisk after some integer [closed]

You can do with a count variable, e.g.: public static void main(String[] args) throws Exception{ int i; int count = 1; for (i=1;i<=100;i++) { System.out.print(i); if(count % 5 == 0) { System.out.print(“*”); }else if(count % 8 == 0) { System.out.print(“*”); count = 0; } count++; } } 3 solved Print asterisk after some integer [closed]