[Solved] how to get substring items with in arraylist in java

you have two approaches: ArrayList<String> ar = new ArrayList(); ar.add(“UserId”); //adding item to arraylist ar.add(“Directory”); ar.add(“Username”); ar.add(“PhoneNumber”); // approach one using iteration for (Iterator<String> it = ar.iterator(); it.hasNext(); ) { String f = it.next(); if (f.equals(“UserId”)) System.out.println(“UserId found”); } // approach two using a colletion which supports fetching element by key Map<String,String> myMap=new HashMap<>(); for(String … Read more

[Solved] How can I check if the user has installed an app?

Define a method that returns true if the PackageManager can find it: Example: private boolean checkThisApp(String uri) { PackageManager myPackageManager = getPackageManager(); boolean app_installed; try { myPackageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; } and use it in the Activity/Fragment like: boolean isAppInstalled = checkThisApp(“com.facebook.katana”); 1 … Read more

[Solved] Size of C++ vector is invalid

From your non-understable question, I can guess that you want the vector to treat the [] operator as “edit if it is exist or create if it is not”. Some thing like the behavior of [] operator in std::map for example.. You simply can not. It was not designed like this. BTW, you may do … Read more

[Solved] Determine if a number is prime [closed]

You are missing a bracket. If you keep your code clean it will solve the problem. Also in your if statement you are checking if number % 2 != 0. If it does not equal to 0 then it could potentially be a prime number. So I changed it to number % 2 == 0 … Read more

[Solved] Pattern Programmings

Introduction Solved pattern programming is a type of programming that involves solving a problem by breaking it down into smaller, more manageable pieces. It is a powerful tool for problem solving and can be used to solve a wide variety of problems. Solved pattern programming is often used in computer science, engineering, and mathematics. It … Read more

[Solved] How to print key value pair in Laravel using foreach loop [closed]

Your code is a mess. here is a cleaner version without using the models (since you did not say if they are in place) Controller Code public function show_friend_request() { $user_id = auth()->user()->id; $senderIds = DB::table(‘friendships’)->where(‘recipient_id’, $user_id)->where(‘status’, ‘pending’)->pluck(‘sender_id’)->toArray(); $activeRequests = DB::table(‘users’) ->whereIn(‘id’, $senderIds) ->get([‘first_name’,’last_name’]); return view(‘pages.friend_request’)->with(‘activeRequest’, $activeRequests); } Blade Code @foreach($activeRequest as $key => $friend) … Read more

[Solved] How do you put in css? [closed]

Introduction CSS stands for Cascading Style Sheets and is a language used to style webpages. It is used to control the presentation of HTML elements on a webpage, such as font, color, size, and layout. In this article, we will discuss how to put in CSS and the different ways to do so. We will … Read more

[Solved] Logical negation in front of variable c++ [closed]

!ev is evaluated as true if ev converted to bool is false, otherwise false. N3337 5.3.1 Unary operators 9 The operand of the logical negation operator ! is contextually converted to bool (Clause 4); its value is true if the converted operand is false and false otherwise. The type of the result is bool. 2 … Read more

[Solved] Create 2^n variables with a pattern

If you like to create a piece of code having that many different variables with a different name, I suggest you start writing your own code generator. The code below should be a good start. #include <sstream> #include <iostream> #include <string> #include <vector> namespace { template <typename Function> void bitExecutor(int nrOfBits, std::vector<bool> &bits, const Function … Read more