[Solved] Declaring objects name using some loop [closed]

Objects don’t have names – variables have names. When you declare a variable and initialize it (Java): Person alice = new Person(“Alice”, 25); then alice is the name of a variable, not the name of an object. If you need to create objects in a loop and keep track of them, then use an array … Read more

[Solved] How to split an string array element by whitespace, and forming two new arrays?

As you mentioned the split-function can handle this. String[] types = new String[columnNameType.length]; String[] names = new String[columnNameType.length]; for(int i = 0 ; i< columnNameType.length; ++i){ names[i] = columnNameType[i].split(” “)[0]; types[i] = columnNameType[i].split(” “)[1]; } iterate your array and split every element on its own. 1 solved How to split an string array element by … Read more

[Solved] Simple Java mistake [closed]

Lacks Conditional Statement The answer to the mistake in your program is that it’s an unending loop. It’ll always be true because you just asked the value of accountNum and didn’t add conditional statement. Use this code below as replacement to your code and it works. import java.util.Scanner; public class Yehey { public static void … Read more

[Solved] How to search a list and return the specific strings and data associated with it using Java

public HashMap<String, List<String>> getSortedHashMapForEmployees(string searchKeyword,List<yourDtoFromDB> orginalListFromDB) { HashMap<String, List<String>>hashmap=new HashMap<String, List<String>>(); for (List<yourDtoFromDB> orginalList : orginalListFromDB) { if(orginalList.getName().contains(searchKeyword)) { List<String>accountNo=new ArrayList<String>(); if(hashmap.containsKey(orginalList.getName())) { accountNo=hashmap.get(orginalList.getName()); } accountNo.add(orginalList.getAccountNo()); hashmap.put(orginalList.getName(), accountNo); } } return hashmap; } 3 solved How to search a list and return the specific strings and data associated with it using Java

[Solved] Why do I need a temporary variable to store the value of a Random method? [closed]

You shall direct print it. import java.util.Random; public class compountInterest { public static void main(String[] args){ System.out.println(“” + new Random().nextInt(6)); System.out.println(new Random().nextInt(6)); //Appending empty char at start makes no difference } } 6 solved Why do I need a temporary variable to store the value of a Random method? [closed]

[Solved] Generating and sorting a sequence of 20 numbers in an array w/ for loop (Java)

You already import java.util.Arrays why not use that to print out the sequence? Note: I removed the unnecessary import of java.util.Random (you can use revert back to using that if you want, and whatever num was for as I think that made everything more complicated than required. import java.util.Arrays; public class problem1 { public static … Read more

[Solved] Java threading error [closed]

A quick search online reveals that the EntityClientPlayerMP has a constructor: EntityClientPlayerMP(Minecraft par1Minecraft, World par2World, Session par3Session, NetClientHandler par4NetClientHandler) Since that is the only constructor, creating a new object of that class will require you call it with that. solved Java threading error [closed]

[Solved] Regular Expression to count number of pairs in a string [closed]

Try out this: ^(\d)\1*$ or try this ^([0-9])\1*$ please modify the above regex according to your problem.pattern matching if the user enters same digit. \1 matches the first capture group, so the pattern matches whether the digits are repeated in the string. 0 solved Regular Expression to count number of pairs in a string [closed]